[Off] Desafio: Comparador de strings com 3 parametros..
#1

Olб, o titulo jб explica como й o desafio..


Mas como assim 3 parametros?

Exemplo:

pawn Code:
if(CompararStrings("teste","teste","Ola!")) {
        print("teste й igual a teste e nгo й igual a Ola!");
    }
acho que esse teste jб explica kkk

Se o primeiro parametro for igual ao segundo, nгo precisa verificar o terceiro e irб retornar verdadeiro.
Se o primeiro parametro nгo for igual ao segundo e igual ao terceiro irб retornar verdadeiro.
Se o primeiro parametro nгo for igual ao segundo ou terceiro irб retornar falso.

Eu fiz algo bem simples..

Depois eu posto minha versгo
Esperando a de vocкs..
Reply
#2

pawn Code:
stock strcmpfoda(str1[],str2[],str3[]) {
    if(!strcmp(str1,str2)) return true;
    if(!strcmp(str1,str3)) return true;
    return false;
}
Desse geito aew?
Reply
#3

pawn Code:
stock comparatres(str1[], str2[], str3[]){
    if(!strcmp(str1, str2)) {
        return 1;
    }
    else if(!strcmp(str1, str3)) {
        return 1;
    }
    return false;
}
Reply
#4

pawn Code:
stock CompararStrings(str1[], str2[], str3[]) {

    if ( !strcmp(str1, str2) ) return 1;
    else if ( !strcmp(str1, str3) ) return 1;
   
    return 0;
}
Reply
#5

pawn Code:
stock strcmp3(str1[], str2[], str3[]) {
    if(!strcmp(str1, str2, true)) return -1; //Primeiro igual o Segundo
    if(!strcmp(str2, str3, true)) return 1; //Segundo igual o Terceiro
    if(!strcmp(str1, str3, true)) return 2; //Primeiro igual o Terceiro
    return 0; //Nada igual
}
Nгo testei k
Reply
#6

pawn Code:
strcmpEudes(str1[], str2[], str3[])
{
    if(equal(str1[], str2[], false))
    {
        if(equal(str2[], str3[], false))
        {
            print("Todas strings Sгo Iguais");
        }
        else
        {
            print("Str1 e str2 Sгo Iguais e sao diferentes de str3");
        }
    }
    else
    {
        if(equal(str2[], str3[], false))
        {
            print("Str2 e str3 Sгo Iguais e sao diferentes de str1");
        }
        else
        {
            if(equal(str1[], str3[], false))
            {
                    print("Str1 e Str3 sгo iguais e diferentes de str2");
            }
            else
            {
                print("Todas as strings sгo diferentes");
            }
        }
    }

    return 1;
}


stock equal(str1[],str2[],bool:ignorecase) {
    if (strlen(str1)!=strlen(str2)) return false;
    if (strcmp(str1,str2,ignorecase)==0) return true;
    return false;
}
acho q funciona
Reply
#7

й meio ridiculo o topico.. eu sei..

Eu fiz assim:

pawn Code:
stock CompararStrings(string1[], string2[], string3[]) {
    new s[3],
        bool:result;
       
    s[0] = strlen(string1);
    s[1] = strlen(string2);
    s[2] = strlen(string3);

    if(s[0] == s[1]) result = true;
    else if(s[0] != s[1]) {
        if(s[0] == s[2]) result = true;
        else if(s[1] != s[2]) result = false;
    }
    return result;
}
Reply
#8

Quote:
Originally Posted by Input
View Post
й meio ridiculo o topico.. eu sei..

Eu fiz assim:

pawn Code:
stock CompararStrings(string1[], string2[], string3[]) {
    new s[3],
        bool:result;
       
    s[0] = strlen(string1);
    s[1] = strlen(string2);
    s[2] = strlen(string3);

    if(s[0] == s[1]) result = true;
    else if(s[0] != s[1]) {
        if(s[0] == s[2]) result = true;
        else if(s[1] != s[2]) result = false;
    }
    return result;
}
Comparar strings por tamanho e meio que irracional ...

pawn Code:
CompararStrings("123", "321", "456")
Retornara verdadeiro, mesmo as strings sendo diferentes!
Reply
#9

Quote:
Originally Posted by iCasTiel
View Post
Comparar strings por tamanho e meio que irracional ...

pawn Code:
CompararStrings("123", "321", "456")
Retornara verdadeiro, mesmo as strings sendo diferentes!
Fiz o seguinte teste:
pawn Code:
if(CompararStrings("teste","teste","Ola!")) {
        print("teste й igual a teste e nгo й igual a Ola!");
    }
    if(CompararStrings("teste","ola!","teste")) {
        print("teste nгo й igual a ola! mas й igual a teste!");
    }
    if(CompararStrings("sss","ola!","teste")) { print("nгo funciona");}
    else
    {
        print("Nгo sгo iguais..");
    }
e mostrou ser funcional..
Reply
#10

Quote:
Originally Posted by Input
View Post
Fiz o seguinte teste:
pawn Code:
if(CompararStrings("teste","teste","Ola!")) {
        print("teste й igual a teste e nгo й igual a Ola!");
    }
    if(CompararStrings("teste","ola!","teste")) {
        print("teste nгo й igual a ola! mas й igual a teste!");
    }
    if(CompararStrings("sss","ola!","teste")) { print("nгo funciona");}
    else
    {
        print("Nгo sгo iguais..");
    }
e mostrou ser funcional..
Mostrou, porйm nгo й. Sua lуgica estб errada, como jб foi dito acima.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)