-
Notifications
You must be signed in to change notification settings - Fork 1
/
363C.cpp
71 lines (69 loc) · 1.21 KB
/
363C.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
//mandeep singh @msdeep14
//
#include<bits/stdc++.h>
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf INT_MAX
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define msi multiset<int>
#define fr0(i,a,b) for(int i=a;i<b;i++)
#define fr1(i,a,b) for(int i=a;i<=b;i++)
#define frn0(i,a,b) for(int i=b-1;i>=0;i--)
#define frn1(i,a,b) for(int i=b;i>=a;i--)
using namespace std;
const int asize= 100005;
const int mod = 1000000007;
long long int mx=-inf;
long long int mi=inf;
int main(){
string s;
cin>>s;
string ans;
ll n=s.length();
ll count=0;
ans.pb(s[0]);
fr0(i,1,n){
if(s[i]==s[i-1]){
count++;
}
else count=0;
if(count<2){
ans.pb(s[i]);
}
}
count=1;
ll count2=0;
n=ans.length();
string sol;
//cout<<"ans:: "<<ans<<endl;
ll x=1;
for(int i=0;i<n;i+=x){
if(ans[i]==ans[i+1] && i+1<n){
sol.pb(ans[i]);
sol.pb(ans[i+1]);
if(ans[i+2]==ans[i+3] && i+3<n){
sol.pb(ans[i+2]);
x=4;
}
else if(i+2<=n-1){
sol.pb(ans[i+2]);
x=3;
}
else{
//sol.pb(ans[i+2]);
x=3;
}
}
else{
sol.pb(ans[i]);
x=1;
}
}
cout<<sol<<endl;
return 0;
}