Chef and Card Game | CRDGAME | CodeChef
Chef is playing a card game with his friend Morty Smith.
The rules of the game are as follows:
- There are two piles of cards, pile and pile , each with cards in it. Pile belongs to Chef and pile belongs to Morty.
- Each card has one positive integer on it
- The ‘power’ of a card is defined as the sum of digits of the integer on that card
- The game consists of rounds
- In each round, both players simultaneously draw one card each from the top of their piles and the player who draws the card with higher power wins this round and gets a point. If the powers of both players' cards are equal then they get point each.
- The winner of the game is the player who has more points at the end of rounds. If both players have equal number of points then the game ends in a draw.
The game is now over and Chef has told Morty to find the winner. Unfortunately, this task is too complex for him. Help Morty find the winner.
Input:
- First-line will contain , number of test cases.
- The first line of each test case will contain , the number of rounds played.
- The of the next lines of each test case will contain and , the number on the card drawn by Chef and Morty respectively in round .
Output:
For each test case, output two space-separated integers on a new line:
Output
- if Chef wins,
- if Morty wins,
- if it is a draw,
followed by the number of points the winner had.
(If it is a draw then output either player’s points).
Output
followed by the number of points the winner had.
(If it is a draw then output either player’s points).
Constraints
Subtasks
- points: No additional constraints
Sample Input:
2
3
10 4
8 12
7 6
2
5 10
3 4
2
3
10 4
8 12
7 6
2
5 10
3 4
Sample Output:
0 2
2 1
0 2
2 1
Explanation:
Test Case :
Round :
Chef’s card has power = ,
Morty’s card has power .
Therefore, Morty wins the round.
Round :
Chef’s card has power ,
Morty’s card has power = .
Therefore, Chef wins the round.
Round :
Chef’s card has power ,
Morty’s card has power .
Therefore, Chef wins the round.
Therefore, Chef wins the game with points (Morty has point).
Test Case :
Round :
Chef’s card has power ,
Morty’s card has power .
Therefore, Chef wins the round.
Round :
Chef’s card has power ,
Morty’s card has power .
Therefore, Morty wins the round.
Therefore, the game ends in a draw and both players have point each.
Morty’s card has power .
Therefore, Morty wins the round.
Morty’s card has power = .
Therefore, Chef wins the round.
Morty’s card has power .
Therefore, Chef wins the round.
Morty’s card has power .
Therefore, Chef wins the round.
Morty’s card has power .
Therefore, Morty wins the round.
Solution (C++ 14)
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int num;
cin>>num;
int chef_count=0, Morty_count=0;
int A,B;
while(num--)
{
int count_A=0,count_B=0;
cin>>A>>B;
while(A!=0)
{
count_A+=A%10;
A=A/10;
}
while(B!=0)
{
count_B+=B%10;
B=B/10;
}
if(count_A>count_B)
chef_count++;
else if(count_A<count_B)
Morty_count++;
else
{
chef_count++;
Morty_count++;
}
}
if(chef_count>Morty_count)
cout<<0<<" "<<chef_count<<endl;
else if(chef_count<Morty_count)
cout<<1<<" "<<Morty_count<<endl;
if(chef_count==Morty_count)
cout<<2<<" "<<Morty_count<<endl;
}
return 0;
}

Comments
Post a Comment