-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3.cpp
65 lines (48 loc) · 1.08 KB
/
day3.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
#include<bits/stdc++.h>
#include <string>
using namespace std;
bool search(string s1, string coll[])
{
int flag=0;
for(int i=0;i<10;i++)
{
if(coll[i]==s1)
{
flag=1;
break;
}
}
if(flag==1) return true;
else return false ;
}
int minLength(string s, int n) {
int times=n;
string collection[]={"12", "21", "34", "43", "56", "65", "78", "87", "09", "90"};
int length=n;
if (n==1)
return 1;
else
{
for(int i=0;i<times-1;i++)
{
for(int j=0;j<s.size();)
{
if( search(s.substr(j,2),collection)==true )
{
length=length-2;
s.erase(s.begin()+j , s.begin() +j+2);
cout<<s<<"\n";
break;
}
else j=j+1;
}
}
}
return length;
}
int main(){
string str;
getline(cin, str);
int minlength=minLength(str, str.size());
cout<<minlength;
}