1024: Single digit statistical time limit: 1 Sec memory limit: MB
Submitted: The resolution: 235
Submitted State [Discussion Version] Title Description
Given a k-bit integer n = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,..., k-1, dk-1>0), write the program to count the number of occurrences of each of the different digit digits. For example: given n = 100311, there are 2 0, 3 1, and one 3.
Input
Each input contains 1 test cases, a positive integer n of no more than 1000 bits.
Output
For each of the different single digit numbers in n, output the digit D and the number of occurrences of M in N in a row in d:m format. Required to be output in ascending order of D.
Sample input
100311
Sample output
0:21:33:1
Hint Source
5053
#include <iostream>
using namespace Std;
int main () {
String str;
int i,data,a[10]={0};
cin>>str;
for (i=0;str[i]!= ' n '; i++) {
data=str[i]-' 0 ';
a[data]++;
}
for (i=0;i<10;i++) {
if (a[i]!=0) {
cout<<i<< ":" <<a[i]<<endl;
}
}
return 0;
}
1024: Single digit statistics