We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目来源
统计 1 ~ n 整数中出现 1 的次数
例如: n为 10,则输出 2 n为11,则输出4 n为100, 则输出21
我们先观察给出n的每个位数出现1的次数, 比如: n = 100‘ 个位数为1的数字:00 '1', 01 '1', 02 '1',03 '1',04 '1',05 '1',06 '1',07 '1',08 '1',09 '1',共10个 十位数为1的数字:0 '1' 0,0 '1' 1,0 '1' 2,0 '1' 3,0 '1' 4,0 '1' 5,0 '1' 6,0 '1' 7,0 '1' 8,0 '1' 9,共10个 百位数为1的数字:'1' 00, 共1个 我们可以看到像11这样的数字,分别在个位数和十位数都被统计了一次, 所以最终,n为100时,出现的1的次数是 10 + 10 + 1 = 21次
通过上面的例子n = 100分析规律:
我们再分析一个n = 111:
我们再分析一个n = 127:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目来源
题目
统计 1 ~ n 整数中出现 1 的次数
例如:
n为 10,则输出 2
n为11,则输出4
n为100, 则输出21
分析
我们先观察给出n的每个位数出现1的次数, 比如:
n = 100‘
个位数为1的数字:00 '1', 01 '1', 02 '1',03 '1',04 '1',05 '1',06 '1',07 '1',08 '1',09 '1',共10个
十位数为1的数字:0 '1' 0,0 '1' 1,0 '1' 2,0 '1' 3,0 '1' 4,0 '1' 5,0 '1' 6,0 '1' 7,0 '1' 8,0 '1' 9,共10个
百位数为1的数字:'1' 00, 共1个
我们可以看到像11这样的数字,分别在个位数和十位数都被统计了一次,
所以最终,n为100时,出现的1的次数是 10 + 10 + 1 = 21次
通过上面的例子n = 100分析规律:
我们再分析一个n = 111:
所以n = 111时,1出现的次数为12 + 12 + 12 = 36
我们再分析一个n = 127:
所以n = 127时,1出现的次数为13 + 20 + 28 = 61
The text was updated successfully, but these errors were encountered: