Educational Codeforces Round 91 (Rated for Div. 2) B. Universal Solution

题目链接:https://codeforces.com/contest/1380/problem/B

题意

你在和一个机器人玩石头剪刀布,给出一个长为 $n$ 的出拳序列,机器人会从某一处开始出拳 $n$ 次,问你要怎么出拳才能赢尽可能多的回合。

题解

全部反制机器人会出的最多的拳即可。

代码

#include <bits/stdc++.h>
using namespace std;

map<char, char> mp{
    {'R', 'P'},
    {'S', 'R'},
    {'P', 'S'}
};

void solve() {
    string s; cin >> s;
    int mx = 0;
    map<char, int> cnt;
    for (char c : s) 
        mx = max(mx, ++cnt[c]);
    for (char c : {'R', 'S', 'P'}) {
        if (cnt[c] == mx) {
            cout << string(s.size(), mp[c]) << "
";
            return;
        }
    }
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}
原文地址:https://www.cnblogs.com/Kanoon/p/13296624.html