小狐狸的X • 2年前
using namespace std; int main(void){
//freopen("1133.in","r",stdin);
//freopen("1133.out","w",stdout);
int n;
int a[10]={0};
cin>>n;
string s;
cin.ignore();
getline(cin,s);
for(int i=0;i<s.length();i++){
if(s[i]=='0') a[0]++;
else if(s[i]=='1') a[1]++;
else if(s[i]=='2') a[2]++;
else if(s[i]=='3') a[3]++;
else if(s[i]=='4') a[4]++;
else if(s[i]=='5') a[5]++;
else if(s[i]=='6') a[6]++;
else if(s[i]=='7') a[7]++;
else if(s[i]=='8') a[8]++;
else if(s[i]=='9') a[9]++;
else continue;
}
for(int i=0;i<10;i++){
cout<<a[i]<<endl;
}
return 0;
}
评论:
int main() {
int n; scanf("%d", &n); int a[n], b[10] = {0}; for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
} for (int i = 0; i < n; i++) {
while (a[i] > 0) {
b[a[i] % 10]++;
a[i] /= 10;
}
} for (int i = 0; i < 10; i++) {
printf("%d\n", b[i]);
} return 0; }
请先登录,才能进行评论