QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555450#8046. Rock-Paper-Scissors Pyramidcode_side-effectRE 0ms3832kbC++20893b2024-09-09 23:27:272024-09-09 23:27:28

Judging History

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

  • [2024-09-09 23:27:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3832kb
  • [2024-09-09 23:27:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 6;
int a[N];

int cmp(char a , char b){
    if(a == b) return 0 ;
    if(a == 'S' &&  b == 'P') return 1;
    else if(a == 'P' &&  b == 'R') return 1;
    else if(a == 'R' &&  b == 'S') return 1;
    else return -1 ; 
}

void solve(){
    string s;
    cin >> s;
    int n = s.size();
    memset(a,0,n+5);
    s = ' ' + s ;
    a[1] = 1;
    for(int i = 2 ; i <= n ; i++){
        if(cmp(s[i] , s[i-1]) == 1) a[i] = a[i-1]+1;
        else if(cmp(s[i] , s[i-1]) == -1) a[i] = a[i-1] - 1 ;
        else a[i] = a[i-1];
    }
    int max = 0,id = -1;
    for(int i = 1 ;i<=n;i++){
        if(max < a[i]){
            max = a[i];
            id = i;
        }
    }
    cout << s[id] << "\n";
}

int main(){
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:


result: