Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- #define F first
- #define S second
- const int MAXN = 1e5 + 10;
- int n, lst[200];;
- string s;
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(0);
- int te; cin >> te;
- while (te--){
- memset(lst, -1, sizeof(lst));
- cin >> n >> s;
- vector<int> vec;
- for (int i = 0; i < n; i++)
- if (s[i] == s[0])
- vec.push_back(i);
- int k = 1;
- while (k < n && s[k] != s[0]) k++;
- int ans = 1;
- while (ans+1 <= k){
- for (int pos: vec) {
- if (pos + ans >= n) goto there;
- if (s[pos+ans] != s[ans]) goto there;
- }
- ans++;
- }
- there:
- cout << s.substr(0, ans) << "\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment