zoukankan      html  css  js  c++  java
  • PAT 1049 Counting Ones [难]

    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 (230​​).

    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也值得注意!自己求的话就不太会求的。

  • 相关阅读:
    Hello World
    查找字符串 fiand
    stdou,write与print()
    python 中 按位 与 & ,| ,^ ,~,
    3*3元素主对角元素之和
    Python random() 函数
    文本颜色设计
    if __name__=="__main__
    join函数
    ProGAN论文的翻译+学习体会
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/9862926.html
Copyright © 2011-2022 走看看