TOPIC

PROBLEM 1287 - 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.

  • deniscostadsc replied 7 years ago

    Para os que não estão conseguindo resolver o problema. Essa entrada me ajudou a pegar os corner cases.

    entrada:

    lo6
    234,657
    
    hi
    ,,,,,5,,5,    4
    2200000000
    00
    2147483647
    2147483648
    214748l3646
    214Ppk748l3646
    20 02147483647
    002147483647
    o o2147483647
    OO2147483647
    10000000000
    8589934592
    00000000001
    ,
    0
    00
    0
     0
     0
    1200000000
    2147483647
    2147483648
    oOoOoOoO
    lLlLlLL14748.3646
    988
    19292/s
    li099
    0@0oo
    lo%6
    234,657
    
    ju
    4ooo8[]
    56
    99999999999999999999999999999999999999999999999999

    saída:

    106
    234657
    error
    error
    554
    error
    0
    2147483647
    error
    error
    error
    error
    2147483647
    2147483647
    2147483647
    error
    error
    1
    error
    0
    0
    0
    0
    0
    1200000000
    2147483647
    error
    0
    error
    988
    error
    error
    error
    error
    234657
    error
    error
    error
    56
    error
    MOD
  • fbuff0 replied 8 years ago

    Alguém pode ajudar ? Meu código funciona com os casos testes, mas está dando WA

    while True:
        try:
            achou = False
            nova = ""
            ent = raw_input()
            if ent == "":
                achou = True
            else:
                for x in ent:
                    if x not in "0123456789, lOo":
                        achou = True
                        break   
            if achou:
                print "error"
            else:
                for i in ent:
                    if i in "0123456789":
                        nova+=i
                    elif i == "o" or i == "O":
                        nova += "0"
                    elif i == "l":
                        nova += "1"
                if int(nova) > 2147483647:
                    print  "error"
                else:
                    print int(nova)
        except:
            break
  • Shoonkey replied 7 years ago

    Recebo WA 30%. Já fiz o teste com os inputs do uDebug, e com os testes da própria descrição do problema, e todas funcionam. Alguém tem ideia do porquê?

    #include <iostream>
    #include <string>
    #include <cctype>
    
    using namespace std;
    
    int main(){
    
        string batata;
    
        while(getline(cin, batata)){
    
            string numero;
            bool positive = true;
    
            for(int i = 0; i < batata.length(); i++){
    
                if(isdigit(batata.at(i)))
                    numero += batata.at(i);
                else if (batata.at(i) == 'o' || batata.at(i) == 'O')
                    numero += '0';
                else if(batata.at(i) == 'l')
                    numero += '1';
                else if(batata.at(i) == '-')
                    positive = false;
    
            }
    
            if(!positive || numero == "")
                cout << "error" << endl;
            else {
    
                try {
                    cout << stoi(numero) << endl;
                } catch (...){
                    cout << "error" << endl;
                }
    
            }
    
        }
    
        return 0;
    }
  • drangelp replied 7 years ago

    Tomei w.a. 20¨%. Alguém poderia ajudar?

    #include <bits/stdc++.h>
    
    using namespace std;
    
    char maxx[] = {"2147483647"};
    
    bool verifica (string s)
    {
        if ((int) s.size () > 10)
            return false;
    
        if ((int) s.size () < 10)
            return true;
    
        for (int i = 0; i < 10; i++)
        {
            if (s[i] < maxx[i])
                return false;
        }
    
        return true;
    }
    
    int main ()
    {
        bool erro;
        long double num;
        string s, ans;
    
        while (true)
        {
            erro = false;
            getline (cin, s);
    
            if (cin.eof ())
                break;
    
            for (int i = 0; i < (int) s.size () && !erro; i++)
            {
                if (s[i] == '-')
                    erro = true;
                else if (s[i] == 'O' || s[i] == 'o')
                    ans += '0';
                else if (s[i] == 'l')
                    ans += '1';
                else if (s[i] != ' ' && s[i] != ',')
                {
                    if (isdigit (s[i]))
                        ans += s[i];
                    else
                        erro = true;
                }
            }
    
            if (ans.empty ())
                erro = true;
    
            if (!erro)
            {
                if (!verifica (ans))
                    cout << "error" << endl;
                else
                    cout << ans << endl;
            }
            else
                cout << "error" << endl;
    
            ans.clear ();
        }
        system ("pause");
        return 0;
    }
  • pdsdlima replied 7 years ago

    Usei os inúmeros casos de teste colocados aqui e meu código passou em todos, mas ainda assim, está dando WA 20%. O que está faltando?

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    #define N 51
    
    int main()
    {
        char str1[N], str2[N];
        int i,j, cont, size_str1=0, size_str2=0;
    
        while(fgets(str1, sizeof(str1), stdin)!=NULL)
        {
            size_str1 = strlen(str1);
            size_str2 = strlen(str2);
    
            j=0;
            cont=0;
    
            for(i=0; i<size_str1; i++)
            {
                str2[i]=0;          
                if(str1[i]=='O'||str1[i]=='o')
                {
                    str2[j] = '0';
                    j++;
                }
                else if(str1[i]=='l')
                {
                    str2[j] = '1';
                    j++;
                }
                else if(str1[i]==','||str1[i]==' ')
                 continue;
                else if(isdigit(str1[i]))
                {
                    str2[j]=str1[i];
                    j++;
                }       
                else if(isalpha(str1[i])||ispunct(str1[i]))
                {
                    cont++;
                    break;
                }
            }
            if(cont>0||j==0||strtol(str2,NULL,10)>2147483647)
                puts("error");
            else
                printf("%ld\n", strtol(str2,NULL,10));
        }
        return 0;
    }
  • rvissotto replied 7 years ago

    Problema resolvido. O L maiúsculo não conta como 1 e faltava testar o caso do overflow.

  • gdmotta replied 7 years ago

    valeu Rafael Vissotto passou aqui 100%. Abraço

  • rvissotto replied 7 years ago

    E aí Geraniel, beleza?

    No teu código só está faltando fazer um loop ao ler o que o usuário digita. Poderão haver varias entradas.

    Segue o exemplo, basta envolver o getline em um laço com o while:

    while (getline(cin, p))

    Também não se esqueça que no URI é necessário quebrar a linha quando você "printa" a resposta.

    cout << "error" << endl;
    /*...*/
    cout << p << endl;

    Testei o código com estas alterações é passou 100%.

  • rvissotto replied 7 years ago

    Minha submissão retorna Wrong answer (30%), mas não consegui identificar o erro. Sou iniciante em python, estou precisando de ajuda. Segue o código abaixo:

    import fileinput
    
    for texto in fileinput.input():
    
        texto = texto.replace("o", "0");
        texto = texto.replace("O", "0");
        texto = texto.replace("l", "1");
        texto = texto.replace("L", "1");
        texto = texto.replace(",", "");
        texto = texto.replace(" ", "");
    
        try:
            valor = int(texto)
            print(valor)
        except:
            print("error")
  • gdmotta replied 7 years ago

    #include<iostream>
    #include <string>
    
    using namespace std;
    
    string loop ( string p){
    
    string s="";
    bool virgula = false;
    
        if(p.size() == 0)return "error";
    
        for(char c : p){
                if(c == 'l'){
                    s += '1';
                } else if(c=='o'|| c=='O'){
                    s+='0';
                }else if(c == ','){
                    virgula = true;
                    continue;
    
                }else if(isdigit(c)){
                    s+= c;
                }else if(isalpha(c)|| isxdigit(c) || ispunct(c)){
                    return "error";
                }
            }
    
            const char *c = s.c_str();
                while((char) *c == '0'){
                    c++;
                }
    
            s = c;
    
         if(virgula == true && s.size()==0)return "error";
         if(s.size() > 10)return "error";
         if(s.size()==0 && virgula == false ) return "0";
    
         if(stoll(s)<=2147483647)
            return s;
         else
            return "error";
    
    }
    
    int main(){
    
        string p;
    
       getline(cin, p);
    
        if(p.size() == 0 || p == " "){
            cout<< "error";
        }else{
            p = loop(p);
            cout << p;
        }
    
        return 0;
    }

    Estou recebendo Wrong answer (100%), alguém ai poderia me ajudar em um caso de teste? os que encontrei no forum passaram.

  • ssilvino replied 7 years ago

    Alguém pode me ajudar, teste para todos os casos teste postados aqui. Recebi a resposta certa em todos. Além disso teste vários casos criados por mim. Obrigado.

    #include <cstdio>
    #include <cstring>
    #include <cctype>
    #include <cstdlib>
    using namespace std;
    
    int verifica(char *s)
    {
        for (int i =0; s[i] != '\0'; i++)
            if (!isdigit(s[i]) && s[i] != ' ' && s[i] != ',' && s[i] != 'o' && s[i] != 'O' && s[i] != 'l')
                return 1;
        return 0;
    }
    
    int main()
    {
        char entrada[100];
    
        while (gets(entrada))
        {
            // Se a entrada eh vazia ou tem algo diferente do permitido
            if (strlen(entrada) == 0 || verifica(entrada))
                printf("error\n");
            else
            {
                int i, j = 0;
                char saida[100];
    
                for (i=0; entrada[i] != '\0'; i++)
                {
                    if (entrada[i] == 'l')
                    {
                        saida[j] = '1';
                        j++;
                    }
                    else if (entrada[i] == 'O' || entrada[i] == 'o')
                    {
                        saida[j] = '0';
                        j++;
                    }
                    else if (isdigit(entrada[i])) // Se eh numero
                    {
                        saida[j] = entrada[i];
                        j++;
                    }
                }
                saida[j] = '\0';
                long saidaNum = atol(saida);
    
                if (saidaNum > 2147483647)
                    printf("error\n");
                else if (saidaNum == 0 && strlen(saida) == 0)  // Se a entrada eh vazia
                    printf("error\n");
                else
                    printf("%ld\n", saidaNum);
            }
        }
    }
  • rseocepython replied 7 years ago

    Cada linha da entrada contém APENAS letras, números, vírgulas e/ou espaço. alguns casos de teste:

    Entrada:

    lo6
    234,657
    
    hi
    ,,,,,5,,5,    4
    2200000000
    00
    2146999999
    ,2147483647,
    llllllllll
    dfdfdfdfdf0lllOO
    0 02147483647
    002147483647
    o o2147483647
    OO2147483647
    0 
    00 
    0
     0 
    dfdf0l,llOO
    dfdfdfdfdf0l,110
    
    12O
    .,1
    10000000000
    8589934592
    00000000001
    1L1L1L00

    Saída:

    106
    234657
    error
    error
    554
    error
    0
    2146999999
    2147483647
    1111111111
    error
    2147483647
    2147483647
    2147483647
    2147483647
    0
    0
    0
    0
    error
    error
    error
    120
    error
    error
    error
    1
    error
  • ldmferreira replied 8 years ago

    É verdade. Consegui resolver, obrigado!

  • Joao40 replied 8 years ago

    Realmente, olhei errado aqui, desculpa. Da uma olhada nos retornos da função strcmp:

    printf("%d\n",strcmp("14", "2147483647")); printf("%d\n",strcmp("34", "2147483647"));

    Esse if(strcmp(saida, "2147483647") <= 0) não ta testando se o valor convertido da saida é menor que 2147483647, só ta testando se os dois valores são iguais, ou então se a primeira letra diferente entre as duas strings tem valor menor em saida do que em "2147483647".

    http://www.cplusplus.com/reference/cstring/strcmp/
  • ldmferreira replied 8 years ago

    }else if(n[i] != ' ' && n[i] != ','){
                    erro = 1;
             }

    Na verdade não, eu coloco erro = 1 se o for diferente de ' ' espaço ou ',' vírgula.

  • Joao40 replied 8 years ago

    Quando tem vírgula, por exemplo, vc coloca erro=1. Nesse caso 234,657 a saída deve ser "234567" e não "error".

  • Joao40 replied 8 years ago

    To usando Windows, mas testei aqui tbm: https://ideone.com/Qdlz3l

  • ldmferreira replied 8 years ago

    Você compilou no Linux? To usando CodeBlocks no Windows e todos os testes deram certo, será que é esse meu problema?

  • Joao40 replied 8 years ago

    Testei seu código e a saída para os exemplos foram:

    106
    error
    error
    error
    error
    error
    0
  • ldmferreira replied 8 years ago

    Estou recebendo WA, mas todos os testes estão dando certo. Alguem pode ajudar?

    Resolvido.
1 of 4