-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2039B.cpp
More file actions
63 lines (53 loc) · 1.47 KB
/
Copy path2039B.cpp
File metadata and controls
63 lines (53 loc) · 1.47 KB
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
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define umap unordered_map
#define f(i, x, n) for(ll i = x; i < n; i++)
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main() {
optimize();
ll t;
cin >> t;
while (t--) {
string s;
cin >> s;
if (s.size()==1) {
cout << -1 << endl;
} else if (s.size()==2) {
if (s[0]==s[1]) {
cout << s << endl;
} else {
cout << -1 << endl;
}
} else {
bool ok = false;
string ans = "";
for (ll i = 0; i+1 < s.size(); i++) {
if (s[i]==s[i+1]) {
ans.pb(s[i]);
ans.pb(s[i+1]);
ok = true;
break;
}
}
if (ok) {
cout << ans << endl;
continue;
} else {
for (ll i = 0; i+2 < s.size(); i++) {
if (s[i]!=s[i+1] and s[i+1]!=s[i+2] and s[i] != s[i+2]) {
ok = true;
ans.pb(s[i]);
ans.pb(s[i+1]);
ans.pb(s[i+2]);
break;
}
}
ok ? cout << ans << endl : cout << -1 << endl;
}
}
}
}