Para resolver esse problema, basta acumular os resultados de Maria e João para cada jogo, lembrando de zerar o placar a cada caso de teste.
#include<stdio.h>intmain(){int N, R, maria, joao;while(scanf("%d",&N)){if(!N) break; maria =0, joao =0;for(int i =0; i < N; ++i){scanf("%d",&R);if(R) ++joao;else++maria; }printf("Mary won %d times and John won %d times\n", maria, joao); }return0;}
#include<iostream>usingnamespace std;intmain(){int N, R, maria, joao;while(cin >> N){if(!N) break; maria =0, joao =0;for(int i =0; i < N; ++i){ cin >> R;if(R) ++joao;else++maria; } cout <<"Mary won "<< maria <<" times and John won "<< joao <<" times"<< endl; }return0;}
var input =require('fs').readFileSync('/dev/stdin','utf8');var lines =input.split('\n');while(lines.length){letN=parseInt(lines.shift());if(!N) break;let maria =lines.shift().trim().split(" ").map((x) =>parseInt(x)).reduce((acc, curr) => (!curr ? acc +1: acc),0);let joao =N- maria;console.log(`Mary won ${maria} times and John won ${joao} times`);}
whileTrue:try: N =int(input()) R = [int(x)for x ininput().strip().split(' ')] maria, joao =0,0for jogo in R:if(jogo ==0): maria +=1else: joao +=1print(f"Mary won {maria} times and John won {joao} times")exceptEOFError:break