-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChefAndCardGame.py
108 lines (91 loc) · 2.88 KB
/
ChefAndCardGame.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
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 A and pile B, each with N cards in it. Pile A belongs to Chef and pile B 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 N 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 1 point each.
The winner of the game is the player who has more points at the end of N 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 T, number of testcases.
The first line of each test case will contain N, the number of rounds played.
The ith of the next N lines of each test case will contain Ai and Bi, the number on the card drawn by Chef and Morty respectively in round i.
Output:
For each test case, output two space separated integers on a new line:
Output
0 if Chef wins,
1 if Morty wins,
2 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).
Constraints
1≤T≤1000
1≤N≤100
1≤Ai,Bi≤109
Subtasks
100 points : No additional constraints
Sample Input:
2
3
10 4
8 12
7 6
2
5 10
3 4
Sample Output:
0 2
2 1
Explanation:
Test Case 1:
Round 1:
Chef’s card has power 1+0 = 1,
Morty’s card has power 4.
Therefore, Morty wins the round.
Round 2:
Chef’s card has power 8,
Morty’s card has power 1+2 = 3.
Therefore, Chef wins the round.
Round 3:
Chef’s card has power 7,
Morty’s card has power 6.
Therefore, Chef wins the round.
Therefore, Chef wins the game with 2 points (Morty has 1 point).
Test Case 2:
Round 1:
Chef’s card has power 5,
Morty’s card has power 1+0=1.
Therefore, Chef wins the round.
Round 2:
Chef’s card has power 3,
Morty’s card has power 4.
Therefore, Morty wins the round.
Therefore, the game ends in a draw and both players have 1 point each.
"""
# SOLUTION
test_cases = int(input())
while test_cases > 0 :
chef , morty = 0 , 0
score = [0,0]
N = int(input())
while N > 0 :
num = list(map(int, input().split()))
num[0] = sum(map(int,str(num[0])))
num[1] = sum(map(int,str(num[1])))
if num[0] > num[1] :
score[0] += 1
elif num[1] > num[0] :
score[1] += 1
else :
score[0] += 1
score[1] += 1
N -= 1
if score[0] > score[1] :
print("0",score[0])
elif score[1] > score[0] :
print("1",score[1])
else :
print("2",score[0])
test_cases -= 1