-
Notifications
You must be signed in to change notification settings - Fork 0
/
2039B.cpp
40 lines (34 loc) · 988 Bytes
/
2039B.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
#include <iostream>
#include <string>
using namespace std;
int main() {
int testCases;
cin >> testCases;
while (testCases--) {
string input;
cin >> input;
int length = input.size();
string result = "-1";
bool isFound = false;
for (int i = 0; i < length - 1; ++i) {
if (input[i] == input[i + 1]) {
result = input.substr(i, 2);
isFound = true;
break;
}
}
if (!isFound) {
for (int i = 0; i < length - 2; ++i) {
char first = input[i];
char second = input[i + 1];
char third = input[i + 2];
if (first != second && first != third && second != third) {
result = input.substr(i, 3);
break;
}
}
}
cout << result << endl;
}
return 0;
}