51nod1009 (1 of the number)

Source: Internet
Author: User

Title Link: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1009

Test instructions: Chinese question eh ~

Ideas: Consider each digit on the occurrence of 1 times, and then sum it up.

Note that the current digit number is 0, 1, 2~9 three cases of the counting method slightly different, think of the other details here is simple ...

Code:

1#include <bits/stdc++.h>2 #definell Long Long3 using namespacestd;4 5 intMainvoid){6ll N, ans=0, gg=1;7CIN >>N;8ll t=N;9      while(t) {Tenll cnt=t%Ten; Onell xy=n/(gg*Ten); A         if(cnt==0){//situation where the current number is 0 -ans+=xy*GG; -}Else if(cnt==1){//situation where the current number is 1 theans+=xy*GG; -ans+=n%gg+1; -}Else{ -ans+= (xy+1) *gg;//The current number is the case of 2~9 +         } -gg*=Ten; +T/=Ten; A     } atcout << ans <<Endl; -     return 0; -}

  

51nod1009 (1 of the number)

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.