From 3496b0ed08c51e37e135e686b1632fd86f930c2c Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Mon, 30 Sep 2024 16:08:27 +0530 Subject: (init): Initialize repository. --- problems/gameofquarters.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problems/gameofquarters.py (limited to 'problems/gameofquarters.py') diff --git a/problems/gameofquarters.py b/problems/gameofquarters.py new file mode 100644 index 0000000..8b0f8c1 --- /dev/null +++ b/problems/gameofquarters.py @@ -0,0 +1,26 @@ +def determine_winner(N, rounds): + alice_wins = 0 + bob_wins = 0 + + for round_info in rounds: + alice_seq, bob_seq, coin_tosses = round_info.split() + + alice_index = coin_tosses.find(alice_seq) + bob_index = coin_tosses.find(bob_seq) + + if alice_index != -1 and (bob_index == -1 or alice_index < bob_index): + alice_wins += 1 + elif bob_index != -1 and (alice_index == -1 or bob_index < alice_index): + bob_wins += 1 + + if alice_wins > bob_wins: + return "Alice wins!" + elif bob_wins > alice_wins: + return "Bob wins!" + else: + return "Draw!" + +N = int(input().strip()) +rounds = [input().strip() for _ in range(N)] + +print(determine_winner(N, rounds)) -- cgit v1.2.3