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 }
  • 相关阅读:
    CF1132G
    CF1129B
    CF1131G
    CF1109D
    CF1110H
    CF1106F
    my.cnf 配置
    mysql 导入导出
    mysql 批量删除表数据
    国内开源镜像站
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2883039.html
Copyright © 2011-2022 走看看