给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
int arr[10] = { 0 };
cin >> str;
for (int i = 0; i < str.size(); i++){
arr[str[i] - '0']++;
}
for (int i = 0; i < 10; i++){
if (arr[i]){
cout << i << ":" << arr[i] << endl;
}
}
cin.get();
cin.get();
}