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 }
  • 相关阅读:
    esp32(M5STACK)在线体验(Ubuntu)
    esp32(M5STACK)程序烧写(Ubuntu)
    在Ubuntu环境下搭建esp32开发环境
    markdown让文字居中和带颜色
    Doxyfile中插入图片
    System.load 与 System.loadLibrary 的使用
    常见mysql的数据迁移
    mysql中有关树的函数
    spring整合quartz实现动态定时器
    javaweb项目中发布webservices服务
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2883039.html
Copyright © 2011-2022 走看看