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

  • 相关阅读:
    数据库连接池
    JDBC事务
    oracle 11g
    python自动化办公1-os模块学习
    python模块学习1
    requests-post请求
    linux学习二-目录文件相关命令
    Linux学习一常见的7个命令及命令的信息查看
    python-文件操作
    异常以及异常处理
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/9862926.html
Copyright © 2011-2022 走看看