QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555468#8046. Rock-Paper-Scissors Pyramidcode_side-effectRE 0ms3804kbC++20884b2024-09-09 23:36:362024-09-09 23:36:36

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
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;
    i64 n = s.size();
    s = ' ' + s ;
    for(int i = 1 ; 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 min = 1e9,id = -1;
    for(int i = 1 ;i<=n;i++){
        if(min > a[i]){
            min = a[i];
            id = i;
        }
    }
    cout << s[id] << "\n";
}

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

詳細信息

Test #1:

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

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:


result: