-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalienabc.cpp
More file actions
58 lines (48 loc) · 1.07 KB
/
alienabc.cpp
File metadata and controls
58 lines (48 loc) · 1.07 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
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
// uncomment the following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int T;
cin >> T;
for (int test = 0; test < T; test++) {
string S, temp;
cin >> S;
// insert your code here
vector<string> letter;
letter.clear();
for (int i=0; i< S.size(); i++) {
temp = "";
if (i != S.size()-1) {
if (S[i] == S[i+1]) {
temp += S[i];
temp += S[i+1];
i++;
} else {
temp = S[i];
}
} else {
temp = S[i];
}
if (count(letter.begin(), letter.end(), temp) == 0) {
letter.push_back(temp);
} else {
letter.push_back("-1");
}
}
if (count(letter.begin(), letter.end(), "-1") == 0) {
for (int i=0; i<letter.size(); i++) {
cout << letter[i] << " ";
}
cout << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}