1021 个位数统计 (15 分)
#include <iostream> #include <string> using namespace std; int main(){ int index, arr[10] = {0}; string num; // 一千位的数字很大所以要用字符串进行转化 getline(cin, num); for (int i = 0; i < num.size(); i++){ index = num[i] - 48; arr[index]++; } for (int i = 0; i < 10; i++){ if (arr[i]) cout << i << ":" << arr[i] << endl; } return 0; }