原题网址:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1001
Probability One | ||||||
| ||||||
Description | ||||||
Number guessing is a popular game between elementary-school kids. Teachers encourage pupils to play the game as it enhances their arithmetic skills, logical thinking, and following-up simple procedures. We think that, most probably, you too will master in few minutes. Here’s one example of how you too can play this game: Ask a friend to think of a number, let’s call it n
0.
Then: 1. Ask your friend to compute n 1 = 3 * n 0 and to tell you if n1 is even or odd. 2. If n 1 is even, ask your friend to compute n 2 = n 1/2. If, otherwise, n 1 was odd then let your friend compute n 2 = (n 1 + 1)/2. 3. Now ask your friend to calculate n 3 = 3 * n 2. 4. Ask your friend to tell tell you the result of n 4 = n 3/9. (n 4 is the quotient of the division operation. In computer lingo, ’/’ is the integer-division operator.) 5. Now you can simply reveal the original number by calculating n 0 = 2 * n 4 if n 1 was even, or n 0 = 2 * n 4 + 1 otherwise. Here’s an example that you can follow: If n 0 = 37, then n 1 = 111 which is odd. Now we can calculate n 2 = 56, n 3= 168, and n 4 = 18, which is what your friend will tell you. Doing the calculation 2 × n 4 + 1 = 37 reveals n 0. | ||||||
Input | ||||||
Your program will be tested on one or more test cases. Each test case is made of a single positive number (0 < n
0 < 1, 000, 000).
The last line of the input file has a single zero (which is not part of the test cases.) | ||||||
Output | ||||||
For each test case, print the following line:
k. B Q Where k is the test case number (starting at one,) B is either ’even’ or ’odd’ (without the quotes) depending on your friend’s answer in step 1. Q is your friend’s answer to step 4. Note: There is a blank space before B. | ||||||
Sample Input | ||||||
37 38 0 | ||||||
Sample Output | ||||||
1. odd 18 2. even 19 |
一道模拟基础题,按照题目步奏来,注意输入和输出与第一题的变化。
#include<stdio.h>
int main()
{
int n0;
int Case = 1;
while(scanf("%d",&n0) != EOF){
if(n0 == 0){
return 0;
}
int n1 = 3*n0;
bool flag;
if(n1%2 == 1){
flag = true;//奇数
}
else{
flag = false;//偶数
}
int n2;
if(!flag){
n2 = n1/2;
}
else{
n2 = (n1+1)/2;
}
int n3 = 3*n2;
int n4 = n3/9;
if(!flag)
printf("%d. even %d\n",Case++,n4);
else
printf("%d. odd %d\n",Case++,n4);
}
return 0;
}