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

时间:2020-07-14 00:26:03   收藏:0   阅读:89

题目链接: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]) << "\n";
            return;
        }
    }
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

 

原文:https://www.cnblogs.com/Kanoon/p/13296624.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!