Penalty Shots: PENALTY

link: https://www.codechef.com/CU1PP0007/problems/PENALTY

It’s the soccer match finals in Chefland and as always it has reached the penalty shotouts. Each team is given 5 shots to make and the team scoring a goal on the maximum number of shots wins the game. If both the teams’ scores are equal, then the game is considered a draw and we would have 2 champions.

Given ten integers A1,A2,…,A10, where the odd indexed integers(A1,A3, A5, A7,A9) represent the outcome of the shots made by team 1 and even indexed integers(A2,A4,A6,A8,A10) represent the outcome of the shots made by team 2 (here Ai=1 indicates that it’s a goal and Ai=0 indicates a miss), determine the winner or find if the game ends in a draw.

Solution:

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t,shots[10];
    cin>>t;
    while(t--)
    {
        ll two_shots=0;
        ll one_shots=0;
        for(ll i=0; i<10;i++){
            cin>>shots[i];
        }
        for(ll j=0 ;j<10;j++)
        {
            if(j%2==0)
            {
                if(shots[j]==1)
                {
                    two_shots ++;
                }
            }
            else if(j%2==1)
            {
                if(shots[j]==1)
                {
                    one_shots ++;
                }
            }
        }
        if(one_shots>two_shots)
        {
            cout<<2<<endl;
        }
        else if(one_shots==two_shots)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<1<<endl;
        }


    }

}
See also  Power M divisibility by 7: PMD7(Assignment)