码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1049 Counting Ones [难]

时间:2018-10-27 21:19:10      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:ble   rip   com   重复   lang   rom   height   sub   sed   

1049 Counting Ones (30 分)

The task is simple: given any positive integer N, you are supposed to count the total number of 1‘s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1‘s in 1, 10, 11, and 12.

Input Specification:

Each input file contains one test case which gives the positive N (2?30??).

Output Specification:

For each test case, print the number of 1‘s in one line.

Sample Input:

12

Sample Output:

5

 题目大意:给出一个数m,计算1~m中的数包含的所有的1的个数。

//我绝对是看过这道题,但是真的想不起来怎么做了,当时就没怎么看懂。数据量这么大,指定不能一个一个算,需要技巧。

//个位是1+十位是1+。。。。。这样会不会有重复?不会吧。

//这个真的好难,看了好久才明白。

技术分享图片

技术分享图片

如何计算left和now和right也值得注意!自己求的话就不太会求的。

PAT 1049 Counting Ones [难]

标签:ble   rip   com   重复   lang   rom   height   sub   sed   

原文地址:https://www.cnblogs.com/BlueBlueSea/p/9862926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!