个位数统计

输入

10031

输出

0:2

1:3

3:1

#include <iostream>
#include <sstream>
#include <cstdio>
using namespace std;

int main() {

	char str[100];
	cin >> str;
	int len = strlen(str);

	int count[10] = { 0 };       //所有数字出现的次数,初始化为0
	for (int i = 0; i < len; i++)
	{
		count[str[i] - '0']++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (count[i] != 0)
		{
			cout << i << ":" << count[i] << endl;
		}
	}
	return 0;
}

  

posted @ 2018-08-05 17:15  道微真理  阅读(71)  评论(0)    收藏  举报