nemo 在和雷姆玩猜拳游戏,游戏一共进行n 轮,每轮双方将进行一次猜拳,胜负规则与现实中的石头剪刀布一致。即便 nemo 已经预知了雷姆在每轮将出的手型,他仍然非常懒惰,想在 n 轮比赛中保持自己的手型不变。现在他想知道在此条件下自己最多能够获胜的场数。
输入描述
第一行一个正整数n,表示游戏轮数.
第二行一个长度为n 的字符串S, 由字符′R′,′S′,′P′ 组成。其中'R' 表示雷姆将在这回合出石头,'S' 表示剪刀,'P' 表示布。
输出描述
一个整数,表示 nemo 最多取得的胜场数。
样例输入
Copy to Clipboard
6 RSPSSP
样例输出
Copy to Clipboard
3
样例解释
如果 nemo 一直出′R′, 那么他会在第二局、第四局和第五局获胜,这种方案共获胜 3 场,是胜场最多的。
数据规模与约定
1≤n≤1000。
#include#define LL long long using namespace std; const int maxn = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 1e9 + 10; const int N = 1e6; int n; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; cin >> s; int count1 = 0,count2 = 0,count3 = 0 ; for(int i = 0;i < n;i ++){ if(s[i] == 'R') count1++; if(s[i] == 'S') count2++; if(s[i] == 'P') count3++; } cout << max(count1,max(count2,count3)) << endl; return 0; }



