Codeforces Round #751 (Div. 2) 的其他题解点我
A. Two Subsequences
题目大意:
给你一个字符串 s。您需要找到两个非空字符串 a 和 b,以满足以下条件:
字符串 a 和 b 都是 s 的子序列。
对于每个索引 i,字符串 s 的字符 si 必须恰好属于字符串 a 或 b 之一。
字符串 a 是字典序最小可能的;字符串 b 可以是任何可能的字符串。
给定字符串 s,打印任何有效的 a 和 b。
思路:
字典序最小当然就是s中的最小字母了,b可以是任意,那么就是s减去a后的字符串了
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
int T;
scanf("%d", &T);
while (T--) {
string s;
cin >> s;
string c = s;
sort(c.begin(), c.end());
int a = s.find(c[0]);
s.erase(s.begin() + a);
cout << c[0] << " " << s << endl;
}
}