Junior 3162 People submit 1468 people rightScore: 100 points00 hours, 00 minutes, 05 seconds
Describe |
Output 7 The number of numbers, including a multiple of 7, and a number containing 7 (such as 17,27,37 ... 70,71,72,73 ... ) Number of |
Knowledge points |
Cycle |
Run time limit |
0M |
Memory limit |
0 |
Input |
A positive integer n. (n not greater than 30000) |
Output |
The number of digits not greater than n with 7, for example, input 20, and 7 for the number including 7,14,17. |
Sample input |
20 |
Sample output |
3 |
This question uses the method comparison general, is the cyclic traversal, may have the simple method, temporarily did not think
Here is the AC code:
1#include <iostream>2 using namespacestd;3 4 BOOLHaveseven (intnum)5 {6 intK;7 while(1)8 {9k=num%Ten;Ten if(k==7) One return true; ANum/=Ten; - if(num==0) - return false; the } - } - - intMain () + { - intN; +Cin>>N; A intI=7; at intRe=0; - while(i<=N) - { - if(i%7==0) -re++; - Else in if(Haveseven (i)) -re++; toi++; + } -cout<<re<<Endl; the *System"Pause"); $}
Huawei Training Topic: beginner-(practice) Pick 7