首页 > 其他 > 详细

小白进阶之路-CF.Edu-91-B

时间:2020-07-17 22:21:07      阅读:61      评论:0      收藏:0      [点我收藏+]

题意:一段只包含‘R,S,P‘的字符串,希望你输出一段字符串使得无论起始位置 pos 在哪,你胜率最大的组合。

错误思路:分字符种类情况分析。(错误原因,只是找到单次比较最大值,但不是全局比较最大值)

正确思路:分字符数量情况分析。选最多的那个的对应字符。

 

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

void solve(){
    string s;cin >> s;
    int ok[5] = {0};
    for(char i : s){
        if(i == R){
            ok[1]++;
        }else if(i == S){
            ok[2]++;
        }else if(i == P){
            ok[3]++;
        }
    }
    int Max = max(ok[1],max(ok[2],ok[3]));
    char ans;
    if(Max == ok[1]){
        ans = P;
    }else if(Max == ok[2]){
        ans = R;
    }else if(Max == ok[3]){
        ans = S;
    }
    int len = s.size();
    while(len--){
        printf("%c",ans);
    }
    printf("\n");
}

int main()
{
    ios::sync_with_stdio(false);
    int t ;cin >> t;
    while(t--) solve();
    return 0;
}

 

小白进阶之路-CF.Edu-91-B

原文:https://www.cnblogs.com/Wise-XiaoWei4/p/13332616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!