March 2022

A1 - Election Result (Easy Version)

Solution

\[\]

Implementation in C++

#include <bits/stdc++.h>

using namespace std;

int main() {
    int t, a, b, c;
    cin>>t;
    
    while (t--) {
        cin>>a>>b>>c;
        
        // Check whether any party has won by majority
        if (a > b+c)
            cout<<"MAJORITY\n";
        else if (b > a+c)
            cout<<"MAJORITY\n";
        else if (c > a+b)
            cout<<"MAJORITY\n";
        else
            cout<<"COALITION\n";
    }
    
    return 0;
}
\[\]

Implementation in Java

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        int t, a, b, c;
        t = scan.nextInt();
        
        while (t-- > 0) {
            a = scan.nextInt();
            b = scan.nextInt();
            c = scan.nextInt();
            
            // Check whether any party has won by majority
            if (a > b+c)
                System.out.println("MAJORITY");
            else if (b > a+c)
                System.out.println("MAJORITY");
            else if (c > a+b)
                System.out.println("MAJORITY");
            else
                System.out.println("COALITION");
        }
    }
}
\[\]

Implementation in Python

t = int(input())
for _ in range(t):
    a, b, c = map(int, input().split())
    
    # Check whether any party has won by a majority
    if a > b+c:
        print('MAJORITY')
    elif b > a+c:
        print('MAJORITY')
    elif c > a+b:
        print('MAJORITY')
    else:
        print('COALITION')
\[\]

Contest Material