Advertisement
Dang_Quan_10_Tin

CAU3 HSGHN L9 2015-2016

Dec 24th, 2021
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #define task "CAU3"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. constexpr int N = 1e2 + 5;
  10. int k;
  11. string x, s[N];
  12.  
  13. void Read()
  14. {
  15.     cin >> k >> x;
  16. }
  17.  
  18. void Solve()
  19. {
  20.     for (int i = 0; i < (int)x.size(); ++i)
  21.     {
  22.         rotate(x.begin(), x.begin() + 1, x.end());
  23.         s[i] = x;
  24.     }
  25.  
  26.     sort(s, s + x.size());
  27.     int m = unique(s, s + x.size()) - s;
  28.  
  29.     if (k > m)
  30.         cout << -1;
  31.     else
  32.         cout << s[k - 1];
  33. }
  34.  
  35. int32_t main()
  36. {
  37.     ios::sync_with_stdio(0);
  38.     cin.tie(0);
  39.     cout.tie(0);
  40.     if (fopen(task ".INP", "r"))
  41.     {
  42.         freopen(task ".INP", "r", stdin);
  43.         freopen(task ".OUT", "w", stdout);
  44.     }
  45.  
  46.     Read();
  47.     Solve();
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement