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 format:
Each input contains 1 test cases, a positive integer n of no more than 1000 bits.
Output format:
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.
Input Sample:
100311
Sample output:
0:21:33:1
Idea: note segment error, array out of bounds
1#include <stdio.h>2 intdata[ One]; 3 intMainintargcChar*argv[])4 {5 Charnumber[1010];6scanf"%s", number);7 for(intI=0; number[i]!=' /'; i++)8 {9data[number[i]- -]++;Ten } One for(intI=0;i<Ten; i++) A { - if(data[i]!=0) - { theprintf"%d:%d\n", I,data[i]); - } - } - return 0; +}
View Code
PAT1021. Single digit statistics (15)