codeforces 284B Cows and Poker Game 思维问题

B. Cows and Poker Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".

Find the number of cows that can currently show their hands without affecting any betting decisions.

Input

The first line contains a single integer, n (2 ≤ n ≤ 2·105). The second line contains n characters, each either "A", "I", or "F". The i-th character is "A" if the i-th player's status is "ALLIN", "I" if the i-th player's status is "IN", or "F" if the i-th player's status is "FOLDED".

Output

The first line should contain a single integer denoting the number of players that can currently show their hands.

Sample test(s)
input
6
AFFAAA
output
4
input
3
AFI
output
1
Note

In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand.

题意很简单。不是‘F’的人伸手,但是剩余的人中不能含有对应的状态‘A’和 ‘I’

直接用O(n)的算法就解决了,统计下 ‘I’和‘A’的个数,这样就可以来回答这个问题了。注意不相等的情况

分别讨论一下I和A的个数,要覆盖到各种情况。

#include<stdio.h>
#include<string.h>
char a[2000000],b[2000000];

int main()
{
   int len1,len2;
   while(scanf("%s",a)!=EOF){
      int f1=1,f2=1;
      scanf("%s",b);
      len1=strlen(a);
      len2=strlen(b);
      if(len1!=len2){printf("NO\n");continue;} //注意不相等的情况
      int i,sum=0;
      for(i=0;i<len1;i++){    //用f1和f2来统计A和I的个数
         if(a[i]=='1')sum++;
      }
      if(sum==0)f1=0;
      sum=0;
      for(i=0;i<len2;i++){
         if(b[i]=='1')sum++;
      }
      if(sum==0)f2=0;
     // printf("%d%d\n",f1,f2);
      if(f1==f2)printf("YES\n");
      else printf("NO\n");


   }

}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值