-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcharlie.in.cpp
61 lines (55 loc) · 957 Bytes
/
charlie.in.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
# include <fstream>
# include <algorithm>
# include <cstring>
# define NR 100005
using namespace std;
ifstream f("charlie.in");
ofstream g("charlie.out");
int i,j,n,m,VV,maxx,tip,niv;
char s[NR];
int st[NR];
void procesare ()
{
while (niv>=3 && st[niv-2]>st[niv-1] && st[niv-1]<st[niv])
{
maxx+=max(st[niv-2], st[niv]);
st[niv-1]=st[niv]; st[niv]=0;
--niv;
}
}
int main ()
{
f>>tip; f.get();
f.getline (s+1, NR); n=strlen(s+1);
if (tip==1)
{
VV=1; i=1;
while (i<=n-2)
{
maxx=max(maxx, VV);
if (s[i]>s[i+1] && s[i+1]<s[i+2])
{
VV+=2; i=i+2;
}
else
{
++i; VV=1;
}
}
if (maxx==1) maxx=0;
g<<maxx<<"\n";
}
else
{
VV=1;
for (i=1; i<=n; ++i)
{
st[++niv]=s[i]-'0';
procesare ();
}
for (i=1; i<=niv; ++i)
g<<st[i];
g<<"\n"<<maxx<<"\n";
}
return 0;
}