QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537362#8046. Rock-Paper-Scissors Pyramidrotcar07WA 15ms10108kbC++14811b2024-08-30 10:58:112024-08-30 10:58:11

Judging History

你现在查看的是最新测评结果

  • [2024-08-30 10:58:11]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:10108kb
  • [2024-08-30 10:58:11]
  • 提交

answer

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

int main(){
    int t;cin>>t;
    while(t--){
        vector<int> v;
        string s;cin>>s;
        auto trans=[&](char c){if(c=='R')return 0;if(c=='P')return 1;return 2;};
        v.push_back(trans(s[0]));
        for(int i=1;i<s.size();i++)if(s[i]!=s[i-1]) v.push_back(trans(s[i]));
        if(v.size()==1)cout<<"RPS"[v[0]]<<'\n';
        else{
            auto win=[&](int x,int y){return x==(y+1)%3;};
            stack<int> st;
            for(auto x:v){
                if(st.empty()) st.push(x);
                else if(st.top()==x);
                else if(win(x,st.top())) st.pop();
                else st.push(x);
            }
            while(st.size()>1) st.pop();
            cout<<"RPS"[st.top()]<<'\n';
        }
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 10108kb

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:

S

result:

wrong answer 1st lines differ - expected: 'R', found: 'S'