Advertisement
at3107

Untitled

Aug 16th, 2020
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n;
  6.     cin>>n;
  7.     string s;
  8.     cin>>s;
  9.     vector<int> a(n,-1),b(n,-1);
  10.     int left=-1,right=-1;
  11.     for(int i=0;i<n;i++)
  12.     {
  13.         if(s[i]=='-' and left!=-1) b[i]=i-left;
  14.         else if(s[i]=='B') left=i;
  15.         else if(s[i]=='A') left=-1;
  16.     }
  17.     for(int i=n-1;i>=0;i--)
  18.     {
  19.         if(s[i]=='-' and right!=-1) a[i]=right-i;
  20.         else if(s[i]=='B') right=-1;
  21.         else if(s[i]=='A') right=i;
  22.     }
  23.     int votea=0,voteb=0;
  24.     for(int i=0;i<n;i++)
  25.     {
  26.         if(s[i]=='A') votea++;
  27.         else if(s[i]=='B') voteb++;
  28.         else
  29.         {
  30.             if(a[i]==-1 and b[i]==-1) continue;
  31.             else if(a[i]!=-1 and b[i]==-1) votea++;
  32.             else if(b[i]!=-1 and a[i]==-1) voteb++;
  33.             else
  34.             {
  35.                 if(a[i]<b[i]) votea++;
  36.                 else if(a[i]>b[i]) voteb++;  
  37.             }
  38.         }
  39.     }
  40.     if(votea>voteb) cout<<'A';
  41.     else if(votea<voteb) cout<<'B';
  42.     else cout<<"Coalition government";
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement