0

Elections are going on, and there are two candidates A and B, contesting with each other.

The way this can be done is explained below:1. The voter queue is denoted by three characters, viz {-, A, B}. The - denotes neutral candidate, A denotes supporter of candidate A and B denotes supporter of candidate B. 2. Supporters of A can only move towards the left side of the queue.3. Supporters of B can only move towards the right side of the queue. 4. Since time is critical, supporters of both A and B will move simultaneously. 5. They both will try and influence the neutral voters by moving in their direction in the queue. If supporter of A reaches the neutral voter before supporter of B reaches him, then that neutral voter will become a supporter of candidate A. 6. Similarly, if supporter of B reaches the neutral voter before supporter of A reaches him, then that neutral voter will become a supporter of candidate B. 7. Finally, if both reach at the same time, the voter will remain neutral. A neutral vote cannot decide the outcome of the election.

15th Aug 2020, 5:27 PM
Sankalp Pandey
Sankalp Pandey - avatar
10 Answers
+ 2
hi friend, your chance is low to get an answer. put your code in playground and post the link. That will increase your chances dramatically.
15th Aug 2020, 5:41 PM
Oma Falk
Oma Falk - avatar
+ 1
Haha... It's the codeVita question
17th Aug 2020, 9:20 AM
Qamber Hasnain
Qamber Hasnain - avatar
0
import java.io.*; import java.util.*; public class HelloWorld { public static void main(String []args) { Scanner s= new Scanner(System.in); int l=s.nextInt(); char c[]=new char[l]; int a=0,b=0; for(int i=0;i<l;i++) { c[i]=s.next().charAt(0); if(c[i]=='A') a++; else if(c[i]=='B') b++; } int n=0,m=l; if(c[0]=='-') { int k=1; while(c[k]=='-') k++; if(c[k]=='A') { for(int i=0;i<k;i++) { c[i]='A'; a++; } } n=k; } if(c[l-1]=='-') { int k=l-2; while(c[k]=='-') k--; if(c[k]=='B') { for(int i=k;i<l;i--) { c[i]='B'; b++; }
15th Aug 2020, 5:27 PM
Sankalp Pandey
Sankalp Pandey - avatar
0
} m=k+1; } int count=1; while(count!=0) { count=0; //int j=n; for(int j=n;j<m;j++) { if((c[j]=='-') && ((c[j+1]=='A') &&(c[j-1]=='B'))) { continue; } else { if((c[j]=='-') && (c[j-1]=='B')) { count++; c[j]='B'; b++; } if((c[j]=='-') && (c[j+1]=='A')) { count++; c[j]='A'; a++; } } j++; } if(count==0) break; } if(a>b) System.out.println("A"); else if(b>a) System.out.println("B"); else System.out.println("Coalition Government"); /*System.out.println(a); System.out.
15th Aug 2020, 5:29 PM
Sankalp Pandey
Sankalp Pandey - avatar
0
This is not giving output
15th Aug 2020, 5:29 PM
Sankalp Pandey
Sankalp Pandey - avatar
0
Sankalp Pandey I think this is your code: https://code.sololearn.com/cjYHR3R2i7dY/?ref=app I tried some testcases like: 3 A - B and they all worked!Can you share a case were there is no output? Btw.: Oma Falk is right, you were lucky to get this answer. I had to copy both of your code-extracts and had to add missing }. It would have been easier if you would have just shared the code directly.....
16th Aug 2020, 7:30 AM
Alexander Thiem
Alexander Thiem - avatar
0
Yes bro 😂 Qamber Hasnain
18th Aug 2020, 3:43 AM
Sankalp Pandey
Sankalp Pandey - avatar
18th Aug 2020, 3:43 AM
Sankalp Pandey
Sankalp Pandey - avatar
0
Alexander Thiem There is no such case because in question it's already mentioned that all neutral votes are not possible . So your code is correct. Can you please tell me my mistakes.
18th Aug 2020, 3:48 AM
Sankalp Pandey
Sankalp Pandey - avatar
0
Sankalp Pandey I just had to copy both of the code extracts you posted here and add them together..... After that there were only some } missing....
18th Aug 2020, 5:43 AM
Alexander Thiem
Alexander Thiem - avatar