QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#240792 | #6617. Encoded Strings I | He2717970784 | WA | 1ms | 3448kb | C++17 | 679b | 2023-11-05 19:07:45 | 2023-11-05 19:07:46 |
Judging History
answer
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string solve(string s) {
int n = s.length();
vector<int>pos(26, -1), num(n, 0);
for (int i = 0; i < n; i++) {
pos[s[i] - 'a'] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
if (pos[j] > i) {
num[i]++;
}
}
}
string ans;
for (int i = 0; i < n; i++) {
ans += 'a' + num[pos[s[i] - 'a']];
}
return ans;
}
int main() {
int n = 0;
cin >> n;
string s,ans;
cin >> s;
for (int i = 0; i < (int)s.length(); i++) {
string res = solve(s.substr(i));
if (res > ans) {
ans = res;
}
}
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3356kb
input:
4 aacc
output:
bbaa
result:
ok single line: 'bbaa'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
3 aca
output:
ba
result:
ok single line: 'ba'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
1 t
output:
a
result:
ok single line: 'a'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3396kb
input:
12 bcabcabcbcbb
output:
cabcababaa
result:
wrong answer 1st lines differ - expected: 'cbacba', found: 'cabcababaa'