题目
把前n(n<=10000)个整数顺次写在一起,123456789101112……,数一数0~9各出现多少次(输出10个整数,分别是0,1,2,……,9出现的次数)
输入
输入一个长度位n的整数
输出
十行,每行输出整数以及次数
样例
输入
0123456789
输出
0 1
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
代码如下:
#include<string>
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char s[10005];
int f[10];
int main()
{
memset(f,0,sizeof(f));//最开始清空
scanf("%s",s);
int len=strlen(s);
double ans=0,counts=0;
for(int i=0;i<len;i++)
f[s[i]-'0']++;//直接记录即可
for(int i=0;i<=9;i++)
printf("%d %d\n",i,f[i]);
return 0;
}