Problem Description
输入一个正整数N,检查N中重复出现的数字,并打印出一份列表,显示每个数字在正整数N中出现的次数。
Input Description
在一行中输入一个正整数n(n<=10^18)。
Output Description
在第一行中输出0到9的数字,每个数字占3位。
在第二行中输出对应数字出现的次数,每个占3位。
Sample Input
41271092
Sample Output
0 1 2 3 4 5 6 7 8 9
1 2 2 0 1 0 0 1 0 1
答案:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
int main()
{
long int N;//N为长整数类型的数
int x;//
scanf("%ld", &N);
for(int i = 0; i < 10; i++)
printf("%3d", i);
printf("\n");
int b[10] = {0};
while(N != 0)
{
x = N % 10;
b[x] = b[x] + 1;
N = N / 10;
}
for(int i = 0; i < 10; i++)
{
printf("%3d", b[i]);
}
printf("\n");
return 0;
}