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; }
相关文章推荐
- hadoop 处理小文件 方式TBD
- LintCode :硬币排成线 II
- JNDI的作用是什么
- blur和focus的运用
- 老李谈爬虫 2
- 老李谈爬虫 1
- Codeforces 617E XOR and Favorite Number (Round #340 (Div. 2) E题) 莫队算法 + 异或基本性质
- 原型模式(Prototype Pattern)
- Android内存泄漏杂谈
- Activity启动模式之launchMode
- Windows与自定义USB HID设备通信说明.
- 在线编辑器调用
- 复旦大学2014--2015学年第二学期(14级)高等代数II期末考试第七大题解答
- Mysql查看编码方式
- [IOS 开发] 强引用(__strong)和 弱引用(__weak)
- 【Mapreduce】以逗号为分隔符的WordCount词频统计
- 获取出口IP的网站
- POJCodeSubmitter_Update
- struts2的常用标签(二)
- iOS开发-进阶:音频播放、录音、视频播放、拍照、视频录制