UVa 1225 Digit Counting---water problem

Source: Internet
Author: User

UVa 1225

The main idea: to write the first n (n<=10000) integers together, 12345678910111213 ..., the number of a number 0-9 each occurrence of how many words

Problem-solving ideas: Using a CNT array to record 0-9 of the number of occurrences of the 10, first to initialize CNT to 0, and then let I from 1 to enumerate to N,

For each I, the number of each position that is treated with live I, and the corresponding CNT subscript on +1

The final output of the CNT array can

/*UVa 1225 Digit Counting---water problem*/#include<cstdio>#include<cstring>intcnt[ the];//Cnt[i] Record number I occurrences//get the number on each bit of n, and in the corresponding cnt+1voidFunintN) {    if(n = =0){        return; }    ++cnt[n%Ten]; Fun (n/Ten);}intMain () {intT, N; scanf ("%d", &t);  while(t--) {scanf ("%d", &N); memset (CNT,0,sizeofCNT);  for(inti =1; I <= N; ++i)        {Fun (i); }         for(inti =0; I <=9; ++i) {printf (i==9?"%d\n":"%d", Cnt[i]); }    }//While (t)    return 0;}
View Code

UVa 1225 Digit Counting---water problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.