QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605780 | #9288. Roman Palindromes | lym# | WA | 0ms | 3556kb | C++20 | 1.7kb | 2024-10-02 19:33:11 | 2024-10-02 19:33:12 |
Judging History
answer
#include<bits/stdc++.h>
using i64 = long long;
void solve() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
std::vector<std::string > ans;
int num = 0;
for (int i = 0; i < n; i ++) {
if (i + 2 < n) {
if (s[i] == 'M' && s[i + 1] == 'C' && s[i + 2] == 'M') {
ans.push_back("MCM");
}
if (s[i] == 'C' && s[i + 1] == 'X' && s[i + 2] == 'C') {
ans.push_back("CXC");
}
if (s[i] == 'X' && s[i + 1] == 'I' && s[i + 2] == 'X') {
ans.push_back("XIX");
}
i += 2;
continue;
}
if (s[i] == 'M') {
int j = i;
std::string t = "";
while (j < n && j - i < 3 && s[j] == 'M') {
t += 'M';
j ++;
}
i = j - 1;
ans.push_back(t);
} else if (s[i] == 'C') {
int j = i;
std::string t = "";
while (j < n && j - i < 3 && s[j] == 'C') {
t += 'C';
j ++;
}
i = j - 1;
ans.push_back(t);
} else if (s[i] == 'D') {
ans.push_back("D");
} else if (s[i] == 'X') {
int j = i;
std::string t = "";
while (j < n && j - i < 3 && s[j] == 'X') {
t += 'X';
j ++;
}
i = j - 1;
ans.push_back(t);
} else if (s[i] == 'L') {
ans.push_back("L");
} else if (s[i] == 'I') {
int j = i;
std::string t = "";
while (j < n && j - i < 3 && s[j] == 'I') {
t += 'I';
j ++;
}
i = j - 1;
ans.push_back(t);
} else if (s[i] == 'V') {
ans.push_back("V");
}
}
std::cout << ans.size() << '\n';
for (auto it : ans) {
std::cout << it << '\n';
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//std::cin >> t;
while (t --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
input:
5 MMXXI
output:
2 X I
result:
wrong answer Not a split