forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubstringswitcheroo.cpp
52 lines (45 loc) · 917 Bytes
/
substringswitcheroo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s1, s2;
cin >> s1 >> s2;
int n = s1.size();
set<vector<int>> s;
for(int i = 0; i < n; i++) {
vector<int> v(26,0);
for(int j = i; j < n; j++) {
v[s2[j]-'a']++;
s.insert(v);
}
}
int lo = 0;
int hi = -1;
for(int i = 0; i < n; i++) {
vector<int> v(26,0);
for(int j = i; j < n; j++) {
v[s1[j]-'a']++;
if(s.count(v)) {
if(j-i > hi-lo) {
lo = i;
hi = j;
}
}
}
}
if(hi == -1) {
cout << "NONE" << endl;
}
else {
for(int i = lo; i <= hi; i++) {
cout << s1[i];
}
cout << endl;
}
}
int main() {
int cases;
cin >> cases;
while(cases--) {
solve();
}
}