Huawei Training Topic: beginner-(practice) Pick 7

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.