Advertisement
pdpd123

Problem 11

Feb 17th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. //CHALLENGE: ACCEPTED
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #define ll long long
  7. using namespace std;
  8. int main() {
  9.     ios_base::sync_with_stdio(false);
  10.     cin.tie(0);
  11.     int t;
  12.     cin >> t;
  13.     while (t--) {
  14.         int n;
  15.         cin >> n;
  16.         string s;
  17.         cin >> s;
  18.         int big[n], small[n];
  19.         for (int i = 0;i < n;i++) {
  20.             big[i] = 0;
  21.             small[i] = 0;
  22.         }
  23.         int cnt = 1;
  24.         for (int i = 0;i < n - 1;i++) {
  25.             if (s[i] == '<') big[i] = cnt++;
  26.         }
  27.         big[n - 1] = cnt++;
  28.         for (int i = n - 2; i >= 0;i --) {
  29.             if (s[i] == '>') big[i] = cnt++;
  30.         }
  31.  
  32.  
  33.         cnt = n;
  34.         for (int i = 0;i < n - 1;i++) {
  35.             if (s[i] == '>') small[i] = cnt--;
  36.         }
  37.         if (s[n - 2] == '>') small[n - 1] = cnt--;
  38.         cnt = 1;
  39.         for (int i = n - 2; i >= 0;i --) {
  40.             if (s[i] == '>') {
  41.                 for (int j = i + 1;j < n - 1;j++) {
  42.                     if (s[j] != '<') break;
  43.                     small[j] = cnt++;
  44.                 }
  45.             }
  46.         }
  47.         if (s[0] == '<') {
  48.             for (int j = 0;j < n - 1;j++) {
  49.                 if (s[j] != '<') break;
  50.                 small[j] = cnt++;
  51.             }
  52.         }
  53.         if (s[n - 2] == '<') small[n - 1] = cnt++;
  54.  
  55.         for (int i = 0;i < n;i++) cout << small[i] << " ";
  56.         cout << endl;
  57.         for (int i = 0;i < n;i++) cout << big[i] << " ";
  58.         cout << endl;
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement