• sicily 1608. Digit Counting


    Description
    Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 < N < 10000) . After that, he counts the number of times each digit (0 to 9) appears in the sequence. For example, with N = 13 , the sequence is:

    12345678910111213

    In this sequence, 0 appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and each digit from 4 to 9 appears once. After playing for a while, Trung gets bored again. He now wants to write a program to do this for him. Your task is to help him with writing this program.


    Input
    The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.

    For each test case, there is one single line containing the number N .


    Output
    For each test case, write sequentially in one line the number of digit 0, 1,...9 separated by a space.

    水题,貌似是机考有一题简单版的(直接统计输入数字本身的数字个数),加一个枚举直接AC

    View Code
     1 #include<stdio.h>
     2 int freq[10];
     3 void count( int n )
     4 {
     5     do{
     6         freq[n % 10]++;
     7         n /= 10;
     8     }while( n != 0 );
     9 }
    10 int main()
    11 {
    12     int i, t, n;
    13     
    14     scanf("%d", &t);
    15     while(t--)
    16     {
    17         for( i = 0; i < 10; i++ )
    18             freq[i]=0;
    19         
    20         scanf("%d", &n);
    21         for( i = 1; i <= n; i++ )
    22             count(i);
    23         
    24         for( i = 0; i < 10; i++ )
    25             if( i != 9 )
    26                 printf("%d ", freq[i]);
    27             else
    28                 printf("%d\n", freq[i]);
    29     }
    30     
    31     return 0;
    32 }
  • 相关阅读:
    热烈祝贺《名博是怎样炼成的》出版
    公司年会在民俗文化村举行
    春节后第一周个人新闻两则
    用asp.net来回收IIS6.0应用程序池
    ComponentArt Web.UI 升级遇到的问题
    今天给博客设计了个博皮
    2009春运购火车票经历
    Android平台下实现一个进程管理器
    【转】Windows平台下Android源码的下载
    【转】 使用git 工具下载android.jar Source Code
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2883039.html
Copyright © 2020-2023  润新知