-
Notifications
You must be signed in to change notification settings - Fork 19
/
election.cpp
88 lines (87 loc) · 864 Bytes
/
election.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
#include<iostream>
using namespace std;
int main()
{
int f;
cin>>f;
string s;
cin >> s;
int i=0;
int v1 = 0;
int v2 = 0;
int j=0;
while(s[j]!='\0')
{
if(s[j] == 'A')
v1++;
else if(s[j] == 'B')
v2++;
j++;
}
while(s[i]=='-')
{
i++;
}
if(s[i]=='A')
{
v1+=i;
}
int start = i;
for(;i<f;)
{
while(s[i]=='-' && i<f)
{
i++;
}
if(i==f)
{
break;
}
if(s[i]=='A')
{
if(start == i)
{
i++;
continue;
}
v1 = v1 + (i-start-1);
start = i;
i++;
continue;
}
start = i;
i++;
while(s[i]=='-' && i<f)
{
i++;
}
if(i == f)
v2 = v2 + (i-start-1);
else
{
if(s[i] =='A')
{
v1 = v1 + (i-start-1)/2;
v2 = v2 + (i-start-1)/2;
start = i;
i++;
}
else
{
v2 = v2 + (i-start-1);
}
}
}
if(v1 > v2)
{
cout << "A" << endl;
}
else if(v1 == v2)
{
cout << "Coalition government" << endl;
}
else
{
cout << "B" << endl;
}
}