18001 Farmer Cat
来源:互联网 发布:百合网 知乎 编辑:程序博客网 时间:2024/06/11 05:39
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”.
输入样例
47 Can7 Can't10 Can10 Can't
输出样例
FodderPastureFodderPasture
思路:奇数(除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;}
0 0
- 18001 Farmer Cat
- cat
- cat
- cat
- cat
- cat
- cat
- cat
- cat
- cat
- cat
- cat
- cat
- Cat
- cat
- cat
- cat
- cat
- 引导界面微场景交互设计与技术实现V2.0
- Android内存泄漏杂谈
- 多线程之NSOperation
- JNDI的作用是什么
- 如何用github上传自己的代码,解决冲突
- 18001 Farmer Cat
- 字符设备驱动、平台设备驱动、设备驱动模型、sysfs的比较和关联
- linux能搭建maven仓库
- Java中的String为什么是不可变的? — String源码分析
- 【Hadoop】HDFS的运行原理
- 图像的局部对比度增强算法
- 把svg的polygon转为path的方法和调整形变的方法
- 100+个多媒体开源项目源码
- 网络——连接到server