Advertisement
Guest User

Untitled

a guest
Jan 11th, 2023
2,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define sz(x) ((int)x.size())
  3. using namespace std;
  4. string s;
  5. int n;
  6.  
  7. void Solve() {
  8.     cin >> s;
  9.     n = sz(s);
  10.  
  11.     if (s[0] == s[1]) {
  12.         cout << s[0] << " " << s[1] << " " << s.substr(2) << '\n';
  13.         return;
  14.     }
  15.     if (s[n - 2] == s[n - 1]) {
  16.         cout << s.substr(0, n - 2) << " " << s[n - 2] << " " << s[n - 1] << '\n';
  17.         return;
  18.     }
  19.  
  20.     if (s[0] < s[1]) {
  21.         for (int i = 1; i < n - 1; i++) {
  22.             if (s[i] > s[i + 1]) {
  23.                 cout << s.substr(0, i) << " " << s[i] << " " << s.substr(i + 1) << '\n';
  24.                 return;
  25.             }
  26.         }
  27.     } else {
  28.         for (int i = 1; i < n - 1; i++) {
  29.             if (s[i] <= s[i + 1]) {
  30.                 cout << s.substr(0, i) << " " << s[i] << " " << s.substr(i + 1) << '\n';
  31.                 return;
  32.             }
  33.         }
  34.     }
  35.  
  36.     cout << ":(\n";
  37. }
  38.  
  39. int main() {
  40.     ios_base::sync_with_stdio(false); cin.tie(nullptr);
  41.     int t;
  42.     cin >> t;
  43.  
  44.     for (int i = 0; i < t; i++) {
  45.         Solve();
  46.     }
  47.  
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement