How to group number by size? -
Banditukas - 14.08.2014
Hi,
I have a ex: variable UZWE[ 10 ];
And there can be any value in any array ex:
Код:
UZWE[ 0 ] = 555;
UZWE[ 5 ] = 255;
UZWE[ 1 ] = 99;
...
And how with what function i can to write into string and show for players highest values?
1.
2.
3.
4.
5.
6.
7.
8.
9
10.
Like TOP 10.
Re: How to group number by size? -
Ihateyou - 14.08.2014
use variable and loop .................
or ****** i think u can find already made functions on samp forums
Re: How to group number by size? -
Banditukas - 14.08.2014
Give link.
Re: How to group number by size? -
AzaMx - 14.08.2014
Quote:
Originally Posted by Banditukas
Give link.
|
******
Re: How to group number by size? -
Banditukas - 14.08.2014
I know ******

but what topic.
Re: How to group number by size? -
CutX - 14.08.2014
well, what you need to do is a simple "bubblesort"
pawn Код:
new UZWE[] = {100,34,2,1124,3642,234,3563,22,51,35};//filling ur array with example values
new tmp;
for (new n=sizeof UZWE; n>1; n=n-1)
{
for (new i=0; i<n-1; i=i+1)
{
if (UZWE[i] < UZWE[i+1])
{
tmp = UZWE[i+1];
UZWE[i+1] = UZWE[i];
UZWE[i] = tmp;
}
}
}
now print it and it'll look like this:
PHP код:
Array ( [0] => 3642 [1] => 3563 [2] => 1124 [3] => 234 [4] => 100 [5] => 51 [6] => 34 [7] => 22 [8] => 2 [9] => 35 )
after that, its sorted from biggest to smallest so you just have to "echo" it in a loop from 0 - 9
or just the ftop 3, it's your choice
example code
php (for nicer looking output)
PHP код:
<?php
$UZWE = array(100,34,2,1124,3642,234,3563,22,51,35);
$tmp;
print_r($UZWE);
echo "<br><br>";
for ($n=count($UZWE)-1; $n>1; $n=$n-1)
{
for ($i=0; $i<$n-1; $i=$i+1)
{
if ($UZWE[$i] < $UZWE[$i+1])
{
$tmp = $UZWE[$i+1];
$UZWE[$i+1] = $UZWE[$i];
$UZWE[$i] = $tmp;
}
}
}
print_r($UZWE);
?>
will generate:
PHP код:
Array ( [0] => 100 [1] => 34 [2] => 2 [3] => 1124 [4] => 3642 [5] => 234 [6] => 3563 [7] => 22 [8] => 51 [9] => 35 )
Array ( [0] => 3642 [1] => 3563 [2] => 1124 [3] => 234 [4] => 100 [5] => 51 [6] => 34 [7] => 22 [8] => 2 [9] => 35 )
Re: How to group number by size? -
Banditukas - 14.08.2014
If example value is %d ? i need to generate number loaded from database.