B

Problem description

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.

Examples

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.

解题思路:每个玩家有两种状态:"ALLIN"或者"IN";只要当前玩家的状态不是"FOLDED",并且其他玩家的状态是"ALLIN"或者"FOLDED",那么当前玩家就可以将他的手放在桌子上,求将手放在桌子上的一共有几个玩家。做法:假设字符'A','F','I'出现的次数依次为a,f,i:①如果i==0,则字符串中只有'A'或'F',即将手放在桌子上的玩家人数为a;②如果i==1,当且仅当某位玩家的状态为"IN",则其他玩家的状态必定是'A'或者'F',即该玩家可以将手放在桌子上,人数为1;③如果i>1,则不满足条件,必定没有玩家的手放在桌子上,人数为0。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 2e5+5;
 4 int n,a=0,f=0,i=0;char s[maxn];
 5 int main(){
 6     cin>>n;getchar();
 7     cin>>s;
 8     for(int j=0;j<n;++j){
 9         if(s[j]=='A')a++;
10         else if(s[j]=='F')f++;
11         else i++;
12     }
13     if(i==0)cout<<a<<endl;//如果没有I,则直接输出A的个数
14     else if(i==1)cout<<1<<endl;//i==1时,其他只有A或F,则此时只有一个人的手放在桌上
15     else cout<<0<<endl;//否则不满足条件即为0个
16     return 0;
17 }
原文地址:https://www.cnblogs.com/acgoto/p/9180896.html