TOPIC

PROBLEM 1329 - URI Fórum 1.0

beecrowd asked on Apr 22 2013

URI Online Judge Fórum 1.0

MOD

This topic was solved and cannot recieve new replies.

  • rddsgomes replied 8 years ago

    Estou recebendo Runtime. Alguém pode ajuda?

    public static void main(String args[]){
            int cont=0,contMary=0,contjohn=0;
    
            Scanner sc = new Scanner(System.in);
    
            cont = sc.nextInt();
            do{
            sc = new Scanner(System.in);
            String linha = sc.nextLine();
            String array[] = new String[cont];
            array = linha.split(" ");
    
            for(int i=0; i<cont; i++)   {
                if(array[i].contains("0")){
                    contMary++;
                }else if(array[i].contains("1")){
                    contjohn++;
                }
            }
    
            System.out.println("Mary won "+contMary+" times and John won "+contjohn+" times");
            contMary = 0;
            contjohn = 0;
            cont = sc.nextInt();
            }while(cont != 0);
        }
  • JessicaDagostini replied 8 years ago

    Boa tarde! Gostaria de saber o que há de errado com meu código. Eu já testei com o toolkit e todas as respostas fecham, e mesmo assim o judge me dá wrong answer 100%.

    #include <iostream>
    
    using namespace std;
    
    int main (){
     int n, x, X = 0, Y = 0;
     cin >> n;
     while (n!=0){
            if(n<0){
                n = n*(-1);
            }
            for(int i=1; i<=n; i++){
                cin >> x;
                if(x==0){
                        X = X + 1;
                }else if(x==1){
                    Y = Y + 1;
                }
            }
            cout << "Mary won " << X << " and John won " << Y << " times" << endl;
            X = 0;
            Y = 0;
            cin >> n;
     }
     return 0;
     }
  • FelipeAlves replied 9 years ago

    Olá pessoal, estou recebendo 10% neste problema! não consegui decifrar o erro! Obs.: não consegui rodar nenhum exemplo no toolkit! Obrigado desde já!

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void){
    
        int n, i, mary, jhon;
        char linha[20100];
    
        while(scanf("%d", &n) && n != 0){
            fflush(stdin);
            gets(linha);
    
            for(i=0,mary=0,jhon=0;linha[i]!='\0';i+=2){
                if(linha[i] == '0'){
                    mary++;
                }else{
                    jhon++;
                }
            }
            printf("Mary won %d times and Jhon won %d times\n", mary, jhon);
        }
    
        return 0;
    }
  • pmargreff replied 9 years ago

    Olá, testei todos os casos, comparei com a toolkit e mesmo assim o código é apontado como 100 % errado, alguém pode me dizer onde estou sendo falho ?

    import java.util.Scanner; //importa classe scanner para fazer a leitura do teclado
    
    /**
     * link : https://www.urionlinejudge.com.br/judge/pt/problems/view/1329
     *
     * @author pmargreff
     */
    class Main {
    
        //método para ler o vetor
        public static int[] leVetor(int tamanho) {
            Scanner teclado = new Scanner(System.in);
            int[] vetor = new int[tamanho];
            for (int i = 0;i < vetor.length; i++) {
                vetor[i] = teclado.nextInt();
            }
    
            return vetor;
        }
    
        public static int contZero(int[] vetor) {
            int total = 0;
            for (int i = 0;i < vetor.length; i++){
                if (vetor[i] == 0)
                    total++;
            }
            return total;
        }
    
        public static int contUm(int[] vetor) {
            int total = 0;
            for (int i = 0;i < vetor.length; i++){
                if (vetor[i] == 1)
                    total++;
            }
            return total;
        }
    
        public static void main(String[] args) {
            Scanner teclado = new Scanner(System.in); //inicializa teclado como leitura padrão para entrada
            int tamanho = 1; // váriavel que conterá o tamanho total do vetor
            int vetor[]; //vetor onde irá ficar armazenado os resultados da jogada
            int zero, um; //contém o número de vitória referente a cada um
    
            while (tamanho != 0) {
    
                tamanho = teclado.nextInt(); //le o tamanho do vetor
    
                if (tamanho > 0) {
                    vetor = new int[tamanho];   //inicializa variáveis com o espaço necessário na memória 
                    vetor = leVetor(tamanho); //le o vetor e salve nele próprio
                    zero = contZero(vetor);
                    um = contUm(vetor);
                    System.out.println("Mary won " + zero + " times and John won " + um + " times");
                }
            }
        }
    }