-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnecklace.cpp
executable file
·91 lines (74 loc) · 1.01 KB
/
necklace.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
int n,c=1,d=1,great1=0,great2=0,i,j;
ifstream fin ("beads.in");
ofstream fout ("beads.out");
string neck;
char s1,s2;
fin>>n;
fin>>neck;
for(i=0;i<n;i++)
{
s1=neck[i];
j=i+1;
while(j!=i)
{
if(c==n)
break;
if(j>(n-1))
j=0;
if((neck[j]==s1)|| (neck[j]=='w'))
c+=1;
else
break;
j+=1;
}
if(i!=0)
{
s2=neck[i-1];
j=i-2;
while(j!=i)
{
if(d==n)
break;
if(j<0)
j=n-1;
if((neck[j]==s2)|| (neck[j]=='w'))
d+=1;
else
break;
j-=1;
}
}
else
{
if(d==n)
break;
s2=neck[n-1];
j=n-2;
while(j!=i)
{
if(j<0)
j=n-1;
if((neck[j]==s2)|| (neck[j]=='w'))
d+=1;
else
break;
j-=1;
}
}
if(c>great1)
great1=c;
if(d>great2)
great2=d;
c=1;
d=1;
}
fout<<great1<<endl<<great2;
return 0;
}