-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShort_Substrings.cpp
More file actions
59 lines (48 loc) · 2.17 KB
/
Copy pathShort_Substrings.cpp
File metadata and controls
59 lines (48 loc) · 2.17 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
/*Short Substrings
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string a consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a.
Bob builds b from a as follows: he writes all the substrings of length 2 of the string a in the order from left to right, and then joins them in the same order into the string b.
For example, if Bob came up with the string a="abac", then all the substrings of length 2 of the string a are: "ab", "ba", "ac". Therefore, the string b="abbaac".
You are given the string b. Help Alice to guess the string a that Bob came up with. It is guaranteed that b was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Input
The first line contains a single positive integer t (1≤t≤1000) — the number of test cases in the test. Then t test cases follow.
Each test case consists of one line in which the string b is written, consisting of lowercase English letters (2≤|b|≤100) — the string Bob came up with, where |b| is the length of the string b. It is guaranteed that b was built according to the algorithm given above.
Output
Output t answers to test cases. Each answer is the secret string a, consisting of lowercase English letters, that Bob came up with.
Example
inputCopy
4
abbaac
ac
bccddaaf
zzzzzzzzzz
outputCopy
abac
ac
bcdaf
zzzzzz
Note
The first test case is explained in the statement.
In the second test case, Bob came up with the string a="ac", the string a has a length 2, so the string b is equal to the string a.
In the third test case, Bob came up with the string a="bcdaf", substrings of length 2 of string a are: "bc", "cd", "da", "af", so the string b="bccddaaf".*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string st1;
for(int i=0;i<n;i++){
cin>>st1;
for(int j=1;j<st1.size();j++){
if(st1[j]==st1[j+1]){
st1.erase(j,1);
}
}
cout<<st1<<endl;
}
return 0;
}