Guest User

SECPASS Author

a guest
Feb 17th, 2019
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1.     #include<bits/stdc++.h>
  2.      
  3.     using namespace std;
  4.      
  5.     typedef long long ll;
  6.     typedef pair<int, int> pii;
  7.      
  8.     #define F first
  9.     #define S second
  10.      
  11.     const int MAXN = 1e5 + 10;
  12.      
  13.     int n, lst[200];;
  14.     string s;
  15.      
  16.     int main(){
  17.         ios::sync_with_stdio(false);
  18.         cin.tie(0);
  19.         int te; cin >> te;
  20.         while (te--){
  21.             memset(lst, -1, sizeof(lst));
  22.             cin >> n >> s;
  23.      
  24.             vector<int> vec;
  25.             for (int i = 0; i < n; i++)
  26.                 if (s[i] == s[0])
  27.                     vec.push_back(i);
  28.      
  29.             int k = 1;
  30.             while (k < n && s[k] != s[0]) k++;
  31.      
  32.             int ans = 1;
  33.             while (ans+1 <= k){
  34.                 for (int pos: vec) {
  35.                     if (pos + ans >= n) goto there;
  36.                     if (s[pos+ans] != s[ans]) goto there;
  37.                 }
  38.                 ans++;
  39.             }
  40.      
  41.     there:
  42.             cout << s.substr(0, ans) << "\n";
  43.         }
  44.         return 0;
  45.     }
Add Comment
Please, Sign In to add comment