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...