Topic describes

Given a k bit integer N = dk – 110 k – 1 +.. + d1101 + d0 (0 or less di 9 or less, I = 0,…, k – 1, dk – 1 > 0) N = d_ {1} k – 10 ^ {1} – k +. + d_110 ^ 1 + d_0 (0 or less d_i 9 or less, I = 0,…, k – 1. D_ {1} k – > 0) N = dk – 110 k – 1 +.. + d1101 + d0 (0 or less di 9 or less, I = 0,…, k – 1, dk – 1 > 0), please write a program of statistics in the unit digit of each number. For example, given N=100311, there are two zeros, three ones, and one three.

Input format: Each input contains 1 test case, that is, a positive integer N with no more than 1000 digits.

Output format: For each different one digit in N, output the digit D and the number of times M in N in the format of D:M. The output is required in ascending order of D.

Example Input: 100311 Example output: 0:2 1:33 3:1

Thought analysis

I also wrote the error code. At that time, I could not find any mistake. Later, I asked my teacher and remembered that if 1024 was entered, the error code was judged to be an integer 1024. Instead of 1, 0, 2, 4, four 😂 test points should be a special case with only one number

AC code

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[10] = {0};
    char c;
    while(cin>>c)
        a[c-'0'] + +;for(int i=0; i<10; i++)if(a[i]! =0)
            cout<<i<<':'<<a[i]<<endl;
    return 0;
}
Copy the code

Error code (can only pass one test point)

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N,a[10] = {0};
    while(cin>>N)
        a[N]++;
    for(int i=0; i<10; i++)if(a[i]! =0)
            cout<<i<<':'<<a[i]<<endl;
    return 0;
}
Copy the code

Make persistent efforts

Come tomorrow or the day after tomorrow at 😁