**
PAT初级1021 个位数统计(C++)**
题目: 思路:数字只有0-9,统计各类数量,最后输出数量不为0的即可(其实本质也类似于桶排序~)
代码:# include# include using namespace std; int main() { string num; cin>>num; int a[10] = {0}; string n=""; for(int i=0;i n = num[i]; if (n=="0") { a[0]++; } else if(n=="1") { a[1]++; } else if(n=="2") { a[2]++; } else if(n=="3") { a[3]++; } else if(n=="4") { a[4]++; } else if(n=="5") { a[5]++; } else if(n=="6") { a[6]++; } else if(n=="7") { a[7]++; } else if(n=="8") { a[8]++; } else if(n=="9") { a[9]++; } n = ""; } for(int j=0;j<10;j++) { if(a[j]!=0) { cout< 结果: PLUS: 其他的统计字符/数字数量相关的问题也可参考此方法,如统计缺失的数字/字符(键盘坏键等问题)
其他的解法(搬运):
https://blog.csdn.net/apple_51720004/article/details/115740744
https://blog.csdn.net/weixin_43778744/article/details/99566351



