QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745650 | #9288. Roman Palindromes | samandarhacker1 | WA | 0ms | 3828kb | C++14 | 1.1kb | 2024-11-14 10:56:29 | 2024-11-14 10:56:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<string> vecThree = {"MMM", "CCC", "XXX", "III", "MCM", "CXC", "XIX"};
vector<string> vecTwo = {"MM", "CC", "XX", "II"};
bool isThreePal(string s){
return find(vecThree.begin(), vecThree.end(), s) != vecThree.end();
}
bool isTwoPal(string s){
return find(vecTwo.begin(), vecTwo.end(), s) != vecTwo.end();
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
vector<string> ans;
int i = 0;
for(; i < n - 2; i++){
if(isThreePal(s.substr(i, 3))){
ans.push_back(s.substr(i, 3));
i += 2;
}else if(isTwoPal(s.substr(i, 2))){
ans.push_back(s.substr(i, 2));
i++;
}else{
ans.push_back(s.substr(i, 1));
}
}
if(i == n - 2 && isTwoPal(s.substr(i, 2))){
ans.push_back(s.substr(i, 2));
}else if(i == n - 1){
ans.push_back(s.substr(i, 1));
}
cout << ans.size() << '\n';
for(int i = 0; i < ans.size(); i++){
cout << ans[i] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 MMXXI
output:
3 MM XX I
result:
ok OK!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 I
output:
1 I
result:
ok OK!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1 V
output:
1 V
result:
ok OK!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 X
output:
1 X
result:
ok OK!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
1 L
output:
1 L
result:
ok OK!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 C
output:
1 C
result:
ok OK!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 D
output:
1 D
result:
ok OK!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 M
output:
1 M
result:
ok OK!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
2 XX
output:
1 XX
result:
ok OK!
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 3828kb
input:
2 LL
output:
0
result:
wrong answer Not a split