karan-and-strings

After the Tatvik Hiring Challenge, Karan's NLP professor has given him another homework. Since Manhattan Associates Hiring Challenge is round the corner and Karan is busy preparing for it, he turns to you for help.

Given a string, replace all the consecutively occurring characters by a single, same character.

Input:

The first line contains the number of test cases T. Each test case contains the string, on a separate line.

Output:

Print the modified string, each on a new line.

Constraints:

1 ≤ T ≤ 100

1 ≤ length(string) < 10^6

SAMPLE INPUT
1
aabbcc

SAMPLE OUTPUT
abc

Source: hackerearth | Difficulty: EASY
Tags: Fundamentals


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
num=int(input())
for g in range(0,num):
	st= input()
	st2="0"
	for i in range(0,len(st)):
		if st2[-1]!=st[i]:
			st2=st2+st[i]
	print(st2[1:])


t=eval(input())
for x in range(t):
	s=input()
	import itertools
	print(''.join(ch for ch, _ in itertools.groupby(s)))


from itertools import groupby
ans=[]
def remove_duplicates(arg):
	unique = (i[0] for i in groupby(arg))
	return ''.join(unique)

for i in range(int(input())):
		ans.append(remove_duplicates(input()))

for res in ans:
	print (res)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import re

count = int(input());
for val in range(0,count):
	input = input()
	input1 = re.sub(r'(.)\1+', r'\1', input);
	print(input1)


tc = int(input())
while tc:
	tc-=1	
	i = input()
	l = []
	l.append(i[0])
	for x in range(1,len(i)):
		if i[x]!=i[x-1]:
			l.append(i[x])
	print(''.join(l))


import sys

numberOfTestCases = int(sys.stdin.readline().strip())
#print numberOfTestCases

for i in range(numberOfTestCases):
	sLine = sys.stdin.readline().strip()
	pre = sLine[0]
	curr = sLine[0]
	sys.stdout.write(pre)
	for j in range( len(sLine) ):
		if sLine[j] == pre:
			continue
		else:
			pre = sLine[j]
			sys.stdout.write(pre)
	print('')


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
T = int(input())
while(T!=0):
	s = input()
	ans = s[0]
	for i in range(1,len(s)):
		if s[i-1]!=s[i]:
			ans = ans+s[i]
	print(ans)
	T=T-1



t=int(input())
for w in range(t):
	s=input()
	s1=''
	for i in range(len(s)-1):
		if s[i]!=s[i+1]:
			s1+=s[i]
	print(s1+s[len(s)-1])
		


from collections import deque, defaultdict, Counter
from math import factorial
from fractions import gcd
from sys import stdin
from itertools import *
import heapq
import string
import re

	
def get():
	return testcase.next().strip()
	


testcase = stdin

# code starts here

T = int(get())
for i in range(T):
	s = get()
	ans = " "
	for i in s:
		if i != ans[-1]:
			ans += i
	print(ans[1:])


T = int(input())

if T in range(1, 101):
	for i in range(T):
		string = input()
		if len(string) in range(1, 10**6):
			newString = ''
			for s in string:
				if newString:
					if not newString[-1] == s:
						newString += s
				else:
					newString = s
			print(newString)


import sys
import string
test=eval(input())
for i in range(test):
	s=input()
	lis=list(s)
	sys.stdout.write(s[0])
	p=s[0]
	for curr in lis[1:]:
		if curr!=p:
			sys.stdout.write(curr)
			p=curr
		else:
			p=curr
	print() 


t=eval(input())
for i in range(t):
	s=input()
	c=s[0]+""
	for j in range(1,len(s)):
		if s[j-1]!=s[j]:
			c+=s[j]
	print(c)
		




import sys
list=[]
t=int(input(''))
for i in range(0,t):
	list.append(input(''))
for a in list:

	j=0
	p=0
	q=1

	l=len(a)
	while q<l:
		if a[p]==a[q]:
			q=q+1
		else:
			print(a[p], end=' ')
			sys.stdout.softspace=0
			p=q
			q=q+1
		if (q==l):
			print(a[q-1], end=' ')
			sys.stdout.softspace=0
	print('\r')





T = int(input())
#print T
for i in range(T):
	s = input()
	#print s
	l = list(s)
	#print l
	n = len(l)
	#print n
	prevch = l[0]
	for i in range(1,n):
		#print i
		if prevch == l[i]:
			#print "same letter"
			l[i] = ''
		else:
			prevch = l[i]
			
	print(''.join(l))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=int(input())
while(t):
	s=input()
	q=[]
	q.append(s[0])
	for i in range(0,len(s)-1):
		if s[i]!=s[i+1]:
			q.append(s[i+1])
	print(''.join(q))
	t-=1
		
		


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def fun():
	tCase = eval(input())
	result =  []
	for i in range(tCase):
			string = input()
			ls = list(string)
			count = 0
			for j in range(len(string)-1):
					if ls[j-count]==ls[j-count+1]:
							del ls[j-count]
							count+=1
			result.append(ls)

	for l in result:
			print(''.join(l))

if __name__=='__main__':
		fun()


for x in range(eval(input())):
	a=input()
	b=len(a)
	c=a[0]
	for i in range(1,b):
		if a[i]!=a[i-1]:
			c+=a[i]
	print(c)        


T = int(input())
#print T
for i in range(T):
	s = input()
	#print s
	l = list(s)
	#print l
	n = len(l)
	#print n
	prevch = l[0]
	for i in range(1,n):
		#print i
		if prevch == l[i]:
			#print "same letter"
			l[i] = ''
		else:
			prevch = l[i]
			
	print(''.join(l))


noOfTestCases = int(input())

def modifiedString(string):
	newString = ""
	prevChar = ""
	curChar = ""
	for c  in string:
		curChar = c
		if(curChar != prevChar):
			newString += curChar
		prevChar = curChar
		
	print(newString)

for caseNo in range(1, noOfTestCases + 1):
	modifiedString(input())





for _ in range(int(input())):
	s = input().strip()
	prev = s[0]
	ans = s[0]
	for x in s[1:]:
		if x == prev:
			continue
		prev = x
		ans += x
	print(ans)	


T = int(input())
j = 0
while j < T:
    
	s = input()
	lst = list()
	lst.append(s[0])
	letter = s[0]
	for i in range(1,len(s)):
		if s[i] != letter:
			lst.append(s[i]),
			letter = s[i]
	print(''.join(lst))
	j = j + 1