UVA-1225. Digit Counting

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/richenyunqi/article/details/82152568

UVA-1225. Digit Counting题解

欢迎访问我的Uva题解目录https://blog.csdn.net/richenyunqi/article/details/81149109

题目描述

UVA-1225. Digit Counting题目描述

题意解析

把1~N这N个数字顺次写在一起,组成一个长字符串,统计出这个字符串中0~9这10个数字各出现了多少次

注意点

输出每行末尾不能有空格,否则会出现Presentation error错误

C++代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T,N,A[10];
    scanf("%d",&T);
    while(T--){
        memset(A,0,sizeof(A));//将A数组所有元素初始化为0
        for(scanf("%d",&N);N>0;--N)//枚举N~1这N个数字
            for(int k=N;k>0;k/=10)
                ++A[k%10];
        for(int i=0;i<10;++i)
            printf("%d%s",A[i],i<9?" ":"");//每行末尾不能有空格
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/richenyunqi/article/details/82152568