18001 Farmer Cat

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值