本文共 475 字,大约阅读时间需要 1 分钟。
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int main(){ char str[1010]; //gets(str); //PAT不能使用gets fgets(str,1010,stdin); int i= 0; while(str[i]!='\n') i++; str[i]='\0'; int len = strlen(str); int count[10] = { 0}; for(int i=0;i<len;i++) { count[str[i]-'0']++; } for(int i=0;i<10;i++) { if(count[i]!=0) printf("%d:%d\n",i,count[i]); } return 0;}
转载地址:http://azph.baihongyu.com/