-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathreduce_string.cpp
More file actions
48 lines (36 loc) · 810 Bytes
/
reduce_string.cpp
File metadata and controls
48 lines (36 loc) · 810 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
46
47
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
string str ;
cin>>str;
int count=0,c=2;
string new_str ="";
do{
new_str = "";
count=0;
for(int i=0;i<str.length();){
if(str[i]==str[i+1])
{
i+=2;
}else{
new_str += str[i];
i++;
}
}
if(new_str=="")
break;
else{
for(int j=0;j<new_str.length()-1;j++)
if(new_str[j]!=new_str[j+1])
count++;
if(count+1==new_str.length())
break;
}
str = new_str;
}while(count!=new_str.length());
if(new_str == "")
cout<<"Empty String";
else
cout<<new_str;
}