Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve() {
- string s;
- cin >> s;
- if (s.size() <= 1) {
- cout << "IMPOSSIBLE" << '\n';
- return;
- }
- vector <int> a(26);
- for (int i = 0; i < s.size(); ++i) {
- a[s[i]-'a']++;
- }
- string temp;
- for (int i = 0; i < s.size(); ++i) {
- for (int j = 0; j < 26; ++j) {
- if (a[j] && 'a' + j != s[i]) {
- temp += 'a' + j;
- a[j]--;
- break;
- }
- }
- }
- if (temp.size() != s.size()) {
- char ch;
- for (int i = 0; i < 26; ++i) {
- if (a[i]) {
- ch = 'a'+i;
- }
- }
- if (!temp.size()) {
- cout << "IMPOSSIBLE" << '\n';
- return;
- }
- char temp_ch = temp[temp.size()-1];
- temp[temp.size()-1] = ch;
- temp += temp_ch;
- }
- if (temp.size() != s.size()) {
- cout << "IMPOSSIBLE" << '\n';
- return;
- }
- for (int i = 0; i < s.size(); ++i) {
- if (s[i] == temp[i]) {
- cout << "IMPOSSIBLE" << '\n';
- return;
- }
- }
- cout << s << '\n';
- cout << temp << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement