Desafio - Faзa sua prуpria funзгo -
arakuta - 10.11.2013
Vou passar um desafio interessante para vocкs:
Criar uma funзгo nova para
floatround, strcmp e floatfract.
Duas regras: tem que ser uma funзгo (stock ou public) e nгo pode conter a funзгo original na funзгo criada por vocк.
Por exemplo:
pawn Код:
printf("Parte decimal de %f й %d",func());
pawn Код:
printf("ABC й igual a ABC? %s",funcao() ? ("Sim") : ("Nгo"));
Dб pra treinar o cйrebro, hehe! Postem os resultados
Re: Desafio - Faзa sua prуpria funзгo -
WLSF - 10.11.2013
pawn Код:
strcmp_will(str1[], str2[])
{
new i = strlen(str1), j = strlen(str2);
if (i - j)
return i - j;
i = 0;
j = 0;
while (str1[i++] && !j)
{
j = str1[i] ^ str2[i];
}
return j;
}
Fiz um rapidinho pro strcmp, vou postar aqui sу pra movimentar o tуpico.
Respuesta: Desafio - Faзa sua prуpria funзгo -
ipsBruno - 10.11.2013
Tem um algoritimo com floatlog que dб pra fazer o round, mas nao lembro direito. Basicamente voce pega o numero de digitos e eleva 10 na n, depois subtrai sobre o valor total e vai dar o numero decimal, entao subtrai o decima do valor total que retorna o valor sem a parte decimal. ~mas nao lembro direito qual cбlculo com floatlog
Mas dб pra fazer o floatround de maneira bruta, atй
pawn Код:
new Float: x = 20.2;
new y;
for(; y < x ; y++) {
}
printf("%d", y - 1);
Re: Desafio - Faзa sua prуpria funзгo -
Juniiro3 - 10.11.2013
pawn Код:
stock Strcmp ( string1[] , string2[] )
{
new
a = strlen ( string1 ),
b = strlen ( string2 ),
result = ( a > b ) ? b : a;
for ( new i ; i < result ; ++ i )
{
if ( string1 [ i ] != string2 [ i ] )
return true;
}
return false;
}
Retorna true se for diferente
Retorna false se for igual
Respuesta: Desafio - Faзa sua prуpria funзгo -
DanDRT - 10.11.2013
Meu codigo:
pawn Код:
stock d_strcmp(_@strO[], _@strT[])
{
new _@rStr = 0, _@strl[2];
_@strl[0] = strlen(_@strO);
_@strl[1] = strlen(_@strT);
if((!_@strl[0] || !_@strl[1]) || (_@strl[0] ^ _@strl[1]))
return _@strl[0] ^ _@strl[1];
new _@i = -1;
while(++_@i ^ _@strl[0])
{
_@rStr ^= _@strO[_@i] + _@strT[_@i];
}
return !!(_@rStr);
}
se for diferente retorna 0,
se for igual retorna 1,
se o tamanho da stringONE for menor que a stringTWO retorna 2,
se o tamanho da stringONE for maior que a stringTWO retorn -1,
se for nulo retorna 3.
Re: Desafio - Faзa sua prуpria funзгo -
arakuta - 11.11.2013
Legal, vou postar aqui as minhas trкs funзхes ^^
pawn Код:
stock Compare(ab[],cd[])
{
new ef,gh;
for(new a; a < strlen(ab); ++a)
ef += ab[a] * (a + 1);
for(new b; b < strlen(cd); ++b)
gh += cd[b] * (b + 1);
if(ef == gh)
return 1;
return 0;
}
Retorna 1 se forem iguais, e 0 se forem diferentes...
pawn Код:
stock fract(Float:source,decimals = 1)
{
new int = floatround(source * floatpower(10,decimals));
new floa = floatround(floatround(source) * floatpower(10,decimals));
return int - floa;
}
public Float:fround(Float:source)
{
new Float:int = source - floatfract(source);
return int;
}
Re: Desafio - Faзa sua prуpria funзгo -
Gyss - 11.11.2013
Nao e tao dificil assim com os TUTORIAS q tem
o do Junior msm
https://sampforum.blast.hk/showthread.php?tid=459871
Respuesta: Desafio - Faзa sua prуpria funзгo -
DanDRT - 12.11.2013
tu ta usando funзгo nativa dentro da funзгo...
arakuta
Re: Respuesta: Desafio - Faзa sua prуpria funзгo -
arakuta - 12.11.2013
Quote:
Originally Posted by DanDRT
tu ta usando funзгo nativa dentro da funзгo...
arakuta ![confused](images/smilies/confused.gif)
|
A regra seria nгo usar a funзгo original dentro dela mesma...
Por exemplo, nгo poderia usar floatround dentro da minha fround, etc.
Respuesta: Re: Respuesta: Desafio - Faзa sua prуpria funзгo -
DanDRT - 12.11.2013
Quote:
Originally Posted by arakuta
A regra seria nгo usar a funзгo original dentro dela mesma...
Por exemplo, nгo poderia usar floatround dentro da minha fround, etc.
|
e uma funзгo precisa da outra na sua podia fazer naturalmente.
Mais se vocк der uma boa olhada vera que tem metodos diferentes.