TOPIC

PROBLEM 1248 - URI Fórum 1.0

beecrowd asked on Feb 8 2013

URI Online Judge Fórum 1.0

MOD

This topic was solved and cannot recieve new replies.

  • Icaro-Lima replied 7 years ago

    Alguém acha o erro? 20% W.A

    #include <iostream>
    //#include <iomanip>
    //#include <time.h>
    //#include <cmath>
    // #include <stdio.h>
    //#include <stdlib.h>
    //#include <cstring>
    #include <cstdio>
    //#include <sstream>
    #include <string>
    //#include <map>
    //#include <vector>
    //#include <list>
    //#include <algorithm>
    //#include <fstream>
    
    using namespace std;
    
    int main()
    {
        int n, tama, tamb;
        string x, a, b;
        bool sucess;
        cin >> n;
        getchar();
        for (;n>0; n--)
        {
            x = a = b = "";
            sucess = 1;
            getline(cin, x);
            getline(cin, a);
            getline(cin, b);
            tama = a.length();
            tamb = b.length();
            for (int i = 0; i < tama; i++)
            {
                if (x.find(a[i]) != -1)
                {
                    x.erase(x.find(a[i]),1);
                }
                else
                {
                    sucess = 0;
                    break;
                }
            }
            if (sucess != 0)
            {
                for (int i = 0; i < tamb; i++)
                {
                    if (x.find(b[i]) != -1)
                    {
                        x.erase(x.find(b[i]), 1);
                    }
                    else
                    {
                        sucess = 0;
                        break;
                    }
                }
                if (sucess == 0)
                {
                    cout << "CHEATER\n";
                }
                else
                {
                    char temp;
                    if (x.length() >= 1)
                    {
                        for (int i = 1; i < x.length() - 1; i++)
                        {
                            for (int k = 0; k < x.length() - i; k++)
                            {
                                if (x[k] > x[k + 1])
                                {
                                    temp = x[k];
                                    x[k] = x[k + 1];
                                    x[k + 1] = temp;
                                }
                            }
                        }
                        cout << x << endl;
                    }
                    else
                    {
                        cout << endl;
                    }
                }
            }
            else
            {
                cout << "CHEATER\n";
            }
        }
        system("pause");
        return 0;
    }
  • Icaro-Lima replied 7 years ago

    Rapaz também estou com W.A 20% mas posso dizer oque eu acho que seja seu erro. Em vez de:

    cin>>dieta;
              cin.ignore(256,'\n');

    Use:

    cin>>dieta;
              cin.ignore();

    Vi isso nesse tutorial: http://www.codigomaster.com.br/desenvolvimento/c-usando-o-cin-ignore

  • antunius replied 8 years ago

    Estou recebendo WA20% Coloquei o getline na segunda entrada e subiu pra WA80%

    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
        int N;
        cin>>N;
        for(;N>0;N--){
              string dieta;
              cin>>dieta;
              cin.ignore(256,'\n');
              bool comeu_demais=false;
              for(int i=0;  i<2;i++){
                string diaria;
                getline(cin,diaria);
    
                for(int j=0;j<diaria.size();j++)
                {
                  if (dieta.find(diaria[j])!=std::string::npos){
                    //std::cout << "Encontrou: " << dieta.find(diaria[j])<< '\n';
                    dieta.erase(dieta.begin()+dieta.find(diaria[j]));
                  }else{
                    comeu_demais=true;
                    break;
                  }
                }
              }
              sort(dieta.begin(),dieta.end());
              if(comeu_demais){
                cout<<"CHEATER"<<endl;
              }else{
                cout<<dieta<<endl;
              }
        }
        return 0;
    }
  • marcelolima381 replied 8 years ago

    Estou ganhando 80% wrong answer, qual o problema no meu código?

    #include <stdio.h>
    #include <string.h>
    void bubbleSort(char *p, int t) {
        int i,j,aux;
            for (i=0;i<t;i++) {
                for (j=t-1;j>i;j--) {
                    if (p[j]<p[j-1]) {
                        aux=p[j];
                        p[j]=p[j-1];
                        p[j-1]=aux;
                    }
                }
            }
    }
    int procuraLetraRepetida(char dieta[],char cafe[],char almoco[]) {
        int i,j,k;
            for (i=0;i<strlen(cafe);i++) {
                for (j=1;j<strlen(cafe);j++) {
                    if (cafe[i]==cafe[j]&&i!=j) {
                        return 0;
                    }
                }
            }
            for (i=0;i<strlen(almoco);i++) {
                for (j=1;j<strlen(almoco);j++) {
                    if (almoco[i]==almoco[j]&&i!=j) {
                        return 0;
                    }
                }
            }
            return 1;
    }
    int procuraLetraEstranha(char dieta[],char cafe[], char almoco[]) {
        int i,j;
        int troca_cafe;
        int troca_almoco;
            for (i=0;i<strlen(cafe);i++) {
                for (j=0;j<strlen(dieta);j++) {
                    if (dieta[j]==cafe[i]) {
                        troca_cafe=1;
                        j=strlen(dieta)-1;
                    }
                    else {
                        troca_cafe=0;
                    }
                }
            }       
            for (i=0;i<strlen(almoco);i++) {
                for (j=0;j<strlen(dieta);j++) {
                    if (dieta[j]==almoco[i]) {
                        troca_almoco=1;
                        j=strlen(dieta)-1;
                    }
                    else {
                        troca_almoco=0;
                    }
                }
            }
            if (troca_almoco==0||troca_cafe==0) {
                return 0;
            }
            return 1;
    }
    void analisaRefeicao(char s1[], char s2[]) {
        int i,j,k;
            for (i=0;i<strlen(s1);i++) {    
                for (j=0;j<strlen(s2);j++) {
                    if (s1[i]==s2[j]) {
                        s1[i]='x';
                    }
                }
            }
    }
    void formataString(char string[]) {
        if (string[strlen(string)-1]=='\n') {
            string[strlen(string)-1]='\0';
        }
    }
    void leDieta(char dieta[], char cafe[], char almoco[]) {
        fgets(dieta,30,stdin);
        formataString(dieta);
        fgets(cafe,30,stdin);
        formataString(cafe);
        fgets(almoco,30,stdin);
        formataString(almoco);
    }
    int main (void) {
        int i,j,k;
        int n;
        int cheater;
        int letra;
            scanf("%i", &n);
        char dieta[30],cafe[30],almoco[30],final[30];   
            getchar();
            for (i=0;i<n;i++) {
                leDieta(dieta,cafe,almoco);
                cheater=procuraLetraEstranha(dieta,cafe,almoco);
                letra=procuraLetraRepetida(dieta,cafe,almoco);
                if (cheater==0||letra==0) {
                    printf("CHEATER\n");
                }
                else {
                    if (cafe[0]=='\0'&&almoco[0]=='\0') {
                        bubbleSort(dieta,strlen(dieta));
                        puts(dieta);
                    }
                    else if (cafe[0]=='\0'&&almoco[0]=='\0'&&dieta[0]=='\0'){
                        printf("\n");
                    }
                    else {
                        analisaRefeicao(dieta,cafe);
                        analisaRefeicao(dieta,almoco);
                        for (j=0,k=0;j<strlen(dieta);j++) {
                            if (dieta[j]>='A'&&dieta[j]<='Z') {
                                final[k]=dieta[j];
                                k++;        
                            }
                        }
                        bubbleSort(final,strlen(final));
                        puts(final);
                    }   
                }   
            }
    }
  • mleao1 replied 8 years ago

    Seu código não imprime nada quando a dieta é vazia e alguém comeu. Por exemplo, nesse caso, deveria ser CHEATER:

    1
    
    A
  • ppaiva replied 8 years ago

    Obrigado!!!

  • ltgoncalves replied 8 years ago

    A saída tem que ser em ordem alfabética.

  • ppaiva replied 8 years ago

    Minha dúvida é nesse caso:

    Por que a saída não é INDE? Eu penso que deveria deletar na string da dieta os elementos de cada string, entretanto ao fazer isso eu obtenho a saída INDE e não a DEIN. Alguém sabe me dizer onde errei na interpretação?

  • ltgoncalves replied 9 years ago

    Consegui cara, muito obrigado!

  • ggroth replied 9 years ago

    Estranho, pq testei teu código com a entrada de exemplo, e a saída foi essa:

    D
    ABEDCS
    CHEATER
    
    DEIN
  • ltgoncalves replied 9 years ago

    Cara, mas meu código faz isso |:

  • ggroth replied 9 years ago

    De acordo com o enunciado

  • ltgoncalves replied 9 years ago

    Código removido após accepted

    Alguém tem ideia do motivo de eu estar recebendo WA(10%)?

  • oman10 replied on Apr 11 2014

    Obrigado.

  • idcdmiranda replied on Apr 10 2014

    no lugar de scanf("%s", s); use gets(s);

  • oman10 replied on Apr 10 2014

    Alguém sabe e pode ajudar?

  • oman10 replied on Apr 9 2014

    Como eu faço a leitura de quando não tem nada para ler? Não estou conseguindo, alguém pode ajudar? uso linguagem C.

    Exemplo de entrada: 1 ABCD

    A

  • crbonilha replied on Aug 6 2013

    Faça os casos de teste do uri e os postados aqui no fórum também, assim você teria percebido que essa entrada faz com que seu programa entre em um laço infinito:

    HUMEAYLN
    LFDXIRCVSGBWKNQUO
    ZTJPEYM

    O erro está nesta parte:

    for(int x = 0 ; x < t.size() ; x++){
            for(int y = 0 ; y < d.size() ; y++){
                if(d[y] == t[x])
                    achou = 1;
            }
            if(!achou){
                cout<<"CHEATER"<<endl;
                x = d.size();
                C = 1;
            }
            achou = 0;
    }

    Não é recomendável você alterar o valor do iterador dentro do laço. Veja, você alterou o valor de x, e isso influi diretamente em quantas vezes o seu laço vai executar.

  • ggroth replied on Jul 10 2013

    Cara, o meu algoritmo não retorna CHEATER e passou. Talvez não existam letras repetidas na entrada, mas eu assumi como se pudessem existir...

  • lsteffen replied on Jul 10 2013

    Por que seguinte caso de teste retorna "CHEATER"?

    1
    AAA //Deve comer 3 'A's
    AA //Comeu 2 no café da manhã
    A //e outro no almoço

    devo assumir que no plano de dieta não vá conter mais que um alimento de cada tipo?

1 of 2