#include <queue> class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求出最终获胜帮派的名称 * @param s string字符串 * @return string字符串 */ queue<char> q; string predictVictory(string s) { // write code here int Rcnt=0,Dcnt=0; for(char i:s){ if(i=='D')Dcnt++; else Rcnt++; q.push(i); } while(!q.empty()){ if(q.front()=='D'){ Rcnt--; }else{ Dcnt--; } q.pop(); } if(Rcnt>Dcnt){ return "Red"; }else{ return "Dark"; } } };
if(Rcnt>Dcnt){
return "Red";
}else{
return "Dark";
}这里的Rcnt=Dcnt时,有可能时Red胜利,但是我这样也过了,可能时测试组测试不准确吧