SA-MP Forums Archive
[Ajuda] Como verificar qual a variбvel com maior valor - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] Como verificar qual a variбvel com maior valor (/showthread.php?tid=596947)



Como verificar qual a variбvel com maior valor - Rhayziin - 24.12.2015

E ai jovens, de boas? Entгo, tenho 9 variбveis(veja o cуdigo abaixo), em cada uma delas estб definido um valor x diferente(ou nгo). O que eu queria saber й como eu faзo pra fazer um tipo de rank, mas eu quero saber apenas quais as variбveis com os valores maiores (como se fosse um rank).

PHP код:
tHand[0][Points] = 32//Maior
tHand[1][Points] = 04;
tHand[2][Points] = 27;
tHand[3][Points] = 21;
tHand[4][Points] = 07;
tHand[5][Points] = 32//Maior (2)
tHand[6][Points] = 29;
tHand[7][Points] = 15;
tHand[8][Points] = 20
Ou seja, eu quero que o cуdigo me diga: a variбvel tHand[0][Points] e a tHand[5][Points] sгo as maiores, pois cada uma tem 32 pontos.

Desde jб agradeзo <3



Re: Como verificar qual a variбvel com maior valor - Artista - 24.12.2015

Vocк pode usar selection sort para ordenar as variбveis.


Re: Como verificar qual a variбvel com maior valor - F1N4L - 24.12.2015

Sei lб, isso foi o que intendi:

Quote:

if(tHand[0][Points] == 32)
{
SendClientMessage(playerid, -1, "ESTБ VARIБVEL Й MAIOR");
}
if(tHand[5][Points] == 32)
{
SendClientMessage(playerid, -1, "ESTБ VARIБVEL Й MAIOR");
}

Isso vai identificar se a variбvel й igual ao valor 32.


Re: Como verificar qual a variбvel com maior valor - Shadoww5 - 25.12.2015

PHP код:
new texto[128];
new 
MAIORVALOR;
for(new 
i9++)
{
    if( 
tHand[i][Points] >= MAIORVALOR  && tHand[i][Points] )
        
MAIORVALOR tHand[i][Points];
}
for(new 
i9i++)
{
    if( 
tHand[i][Points] == MAIORVALOR )
        
format(texto128"%stHand[%d][Points], "textoi);
}
printf("As maiores variбveis sгo: %spois cada uma tem %d pontos"textoMAIORVALOR); 



Re: Como verificar qual a variбvel com maior valor - Rhayziin - 25.12.2015

Quote:
Originally Posted by Artista
Посмотреть сообщение
Vocк pode usar selection sort para ordenar as variбveis.
Eu tinha achado a funзгo Bubblesort, mas valeu mesmo assim.

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
Sei lб, isso foi o que intendi:

Code...

Isso vai identificar se a variбvel й igual ao valor 32.
Nгo era exatamente isso, mas valeu o/

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
PHP код:
new texto[128];
new 
MAIORVALOR;
for(new 
i9++)
{
    if( 
tHand[i][Points] >= MAIORVALOR  && tHand[i][Points] )
        
MAIORVALOR tHand[i][Points];
}
for(new 
i9i++)
{
    if( 
tHand[i][Points] == MAIORVALOR )
        
format(texto128"%stHand[%d][Points], "textoi);
}
printf("As maiores variбveis sгo: %spois cada uma tem %d pontos"textoMAIORVALOR); 
Valeu cara, era isso que eu queria fazer mesmo! +rep


Re: Como verificar qual a variбvel com maior valor - PT - 25.12.2015

Se nao tou em erro podes usar isto: https://sampforum.blast.hk/showthread.php?tid=343172

para isso.