您的位置:首页 > 其它

18001 Farmer Cat

2016-01-27 17:13 204 查看


18001 Farmer Cat

时间限制:1000MS  内存限制:65535K

提交次数:0 通过次数:0

题型: 编程题   语言: 不限定


Description

There are a lot of bulls in SCAU. One of them loves eating fodder. But his owner -- Farmer Cat would not allow him to eat too much fodder, so she plays a game with this bull.
This game is about A SIMPLE MATH PROBLEM : A number between 1 to 230 will be given by the Farmer Cat, and the bull has to tell whether the number can be described by the sum of not less than
two consecutive positive integers or not. If the bull’s answer is right then he can eat the “fodder”, and if not, only “pasture”.
For example, 7 can be described by the sum of 3 and 4. 10 can be described by the sum of 1,2,3 and 4.
For your information, This bull is a genius and he is always able to answer this problem without hesitation. So Farmer Cat asks you for help and write a program to figure out whether
the answer is right or not.



输入格式

The input consists of T test cases.
The number of test cases (T<=200) is given in the first line of the input file.
The next T lines , each line consists a number N (1<=N<230) given by the Farmer Cat and an answer(Can or Can't) given by the bull.



输出格式

The output should contain T lines, each line consists a word:
If the bull’s answer is right,please print out ”Fodder”.
If it’s wrong.please print out “Pasture”.



输入样例

4
7 Can
7 Can't
10 Can
10 Can't



输出样例

Fodder
Pasture
Fodder
Pasture

思路:奇数(除1外)都满足条件,偶数中是2的n次方的数(1,2,4,8,16……)都不满足条件,其它偶数满足!


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main()
{
long long T;
scanf("%lld",&T);
while(T--)
{
long long n,i,j,flag1,flag2;
char judge[10];
scanf("%lld",&n);
getchar();
gets(judge);
if(n%2!=0&&n!=1)
flag1=1;
else
{
while(n%2==0)
{
n=n/2;
}
if(n==1)
flag1=0;
else
flag1=1;
}
if(strcmp(judge,"Can")==0)
flag2=1;
if(strcmp(judge,"Can't")==0)
flag2=0;
if(flag2==flag1)
printf("Fodder\n");
else
printf("Pasture\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: