P1554 梦中的统计
题目背景
Bessie 处于半梦半醒的状态。过了一会儿,她意识到她在数数,不能入睡。
题目描述
Bessie的大脑反应灵敏,仿佛真实地看到了她数过的一个又一个数。她开始注意每一个数码(0…9):每一个数码在计数的过程中出现过多少次?
给出两个整数 M和 N(1<=M,N<=2*10^9),求每一个数码出现了多少次。
输入格式
第 1 行: 两个用空格分开的整数 M 和 N。
输出格式
第 1 行: 十个用空格分开的整数,分别表示数码 0…9 在序列中出现的次数。
输入输出样例
输入
129 137
输出
1 10 2 9 1 1 1 1 0 1
由于要判断0,所以要稍微复杂一点点,先判断i的位数,这里为了图省事使用了goto,以后尽量还是不要出现。
判断位数代码如下:
if(i/1000000000!=0){
goto fir;
}
else if(i/100000000!=0){
goto sec;
}
else if(i/10000000!=0){
goto fou;
}
else if(i/1000000!=0){
goto fiv;
}
else if(i/100000!=0){
goto six;
}
else if(i/10000!=0){
goto sev;
}
else if(i/1000!=0){
goto eig;
}
else if(i/100!=0){
goto nin;
}
else if(i/10!=0){
goto ten;
}
else{
goto mmp;
}
#include<stdio.h>
int main(){
long long int n,m,i=0,j=0,k=0;
long long int num[10]={0,1,2,3,4,5,6,7,8,9},judge[10]={0};
scanf("%ld%lld",&m,&n);
for(i=m;i<=n;i++){
for(j=0;j<=9;j++){
if(i/1000000000!=0){
goto fir;
}
else if(i/100000000!=0){
goto sec;
}
else if(i/10000000!=0){
goto fou;
}
else if(i/1000000!=0){
goto fiv;
}
else if(i/100000!=0){
goto six;
}
else if(i/10000!=0){
goto sev;
}
else if(i/1000!=0){
goto eig;
}
else if(i/100!=0){
goto nin;
}
else if(i/10!=0){
goto ten;
}
else{
goto mmp;
}
fir:if(i/1000000000==num[j]){
judge[j]++;
}
sec:if(i/100000000%10==num[j]){
judge[j]++;
}
fou:if(i/10000000%10==num[j]){
judge[j]++;
}
fiv:if(i/1000000%10==num[j]){
judge[j]++;
}
six:if(i/100000%10==num[j]){
judge[j]++;
}
sev:if(i/10000%10==num[j]){
judge[j]++;
}
eig:if(i/1000%10==num[j]){
judge[j]++;
}
nin:if(i/100%10==num[j]){
judge[j]++;
}
ten:if(i/10%10==num[j]){
judge[j]++;
}
mmp:if(i%10==num[j]){
judge[j]++;
}
}
}
for(i=0;i<=9;i++){
if(i!=9){
printf("%lld ",judge[i]);
}
else{
printf("%lld\n",judge[i]);
}
}
return 0;
}
梦中的统计,我该睡了。。。