INPUT
### The next n lines contain a char value each
c0
c1
...
cn
n20 . ciis the outcome of the ithgame. It can take a value of either A/B. A indicates that this game was won by Player A and B indicates that it was won by Player B. The input will end when a player has won according to the given rules or 20 characters have been given.
OUTPUT
At the end of the input, if player A wins, output “ A”, If player B wins output “B”. If no one has won, output “Tie”
Note: DO NOT output the quotes
Please print a newline( using “cout<<endl;” is one way to do it) after printing your answer
SOLUTION:
int main()
{
int A = 0, B = 0, counter = 0;
char C;
while (counter < 20)
{
cin >> C;
switch (C)
{
case 'A':
A++;
break;
case 'B':
B++;
break;
}
counter++;
}
if (A - B > 1)
{
cout << "A" << endl;
}
else if (A == B)
{
cout << "Tie" << endl;
}
else
{
cout << "B" << endl;
}
return 0;
}
Comments
Post a Comment