C ++ classic programming question #1: contains k numbers of 3, programming

Source: Internet
Author: User

C ++ classic programming question #1: contains k numbers of 3, programming

Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Enter two positive integers m and k, where 1 <m <100000,1 <k <5 to determine whether m can be divisible by 19 and exactly contains k 3. If conditions are met, the output is YES, otherwise, NO is output.

For example, enter:
43833 3
If the conditions are met, the output is YES.

If you enter:
39331 3
Although there are three, but cannot be divisible by 19, does not meet the conditions, should output NO.

Input
M and k values, separated by a single space.
Output
YES is output when the conditions are met, and NO is output when the conditions are not met.
Sample Input
43833 3
Sample output
YES
The Code is as follows:
# Include <iostream> using namespace std; int main () {int m, k; int weishu [] = {, 1}; // uses the recursive idea, then use an array to solve cin> m> k; int number = 0; int temp = m; for (int I = 0; I <5; I ++) {if (temp/weishu [I] = 3) number ++; temp = temp % weishu [I];} if (m % 19 = 0 & number = k) cout <"YES" <endl; elsecout <"NO" <endl; return 0 ;}

The above code is personally tested! Please feel it! Hope you can help beginners !! Sharing is also a pleasure !!! Please relay...

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.