Let us declare two variables, and , representing the number of games won by the first and second players, respectively. For each game, increase by one if the first player wins, and increase by one if the second player wins.
After all games are completed, compare the values of and and print the result.
Algorithm implementation
Read the number of games . Initialize the variables and with zeros — they will store the number of wins for each player.
scanf("%d",&n);
a = b = 0;Read the results of games and update the values of and according to the outcome of each game.
for(i = 0; i < n; i++)
{
scanf("%d %d",&x,&y);
if (x > y) a++;
if (x < y) b++;
}After processing all the games, compare the number of wins of the players and print the final result.
if (a > b) puts("1"); else
if (a < b) puts("2"); else
puts("0");