码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 1225 Digit Counting

时间:2019-01-15 21:33:57      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:style   count   题意   class   int   turn   git   ++   while   

题意是 输入13,计算1到13组成的数字序列1234568910111213,里面的数字从0到9个出现了多少次,注意10是算为1,0个出现一次。

 1 #include "stdio.h"
 2 #include "stdlib.h"
 3 #include "string.h"
 4 int main()
 5 {
 6     int n,arr[10],num,i,j,ex;
 7     scanf("%d",&n);
 8     while(n--)
 9     {
10         for(j=0;j<10;j++)
11         {
12             arr[j]=0;
13         }
14         scanf("%d",&num);
15         for(i=0;i<=num;i++)
16         {
17             ex=i;
18             while(ex>0)//如果ex>=10,就要进行拆分
19             {
20                 j=ex%10;
21                 arr[j]++;
22                 ex=ex/10;
23             }
24         }
25         for(j=0;j<10;j++)
26         {
27             if(j!=0)
28                 printf(" ");
29             printf("%d",arr[j]);
30         }
31         printf("\n");
32     }
33     return 0;
34 }

 

UVA 1225 Digit Counting

标签:style   count   题意   class   int   turn   git   ++   while   

原文地址:https://www.cnblogs.com/fudanxi/p/10274316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!