zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    win7安装ElasticSearch集群
    win7安装Elasticsearch和Elasticsearch-Head插件
    两台Linux服务器之间的文件传输
    Linux常用文本处理命令
    正则表达式
    七一四日
    我站在小河旁,多少次回头望
    马拉松运动员跑步时在想些什么
    什么都会过去的,什么都有结束
    Novernber Rain
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2883039.html
Copyright © 2011-2022 走看看