-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHE_2.java
More file actions
45 lines (35 loc) · 1023 Bytes
/
Copy pathHE_2.java
File metadata and controls
45 lines (35 loc) · 1023 Bytes
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
/* IMPORTANT: class must not be public. */
/* https://www.hackerearth.com/code-monk-array-strings/algorithm/chandu-and-consecutive-letters/
/*
* uncomment this if you want to read input.*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
class TestClass {
public static void main(String args[] ) throws Exception {
/*
* Read input from stdin and provide input before running
*/
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
for (int i = 0; i < N; i++) {
String line1 = br.readLine();
char c[] = line1.toCharArray();
int n = line1.length();
int j=1;
int z =0;
while(j<=n-1&& z<n-1)
{
if(c[j]==c[z])
{
c[j]='0';
j++;
}
else{z=j;j=j+1;}
}
for(int s=0;s<n;s++ )
{if(c[s]!='0'){System.out.print(c[s]);}}
System.out.println();
}
}
}