Return max, and repeating from string array.
#1

I've tried this:
somewhere:
test[3];
test[0] = 12;
test[1] = 11;
test[2] = 44;
new value = ReturnMax(test);

Код:
stock ReturnMax(string[]) {
	new maxi = -1,maxcount,value[2];
	for(new i = 0; i < strlen(string); i++) {
	    if(string[i] > maxi) {
	        maxi = string[i];
            maxcount = 1;
	    } else if(string[i] == maxi) maxcount++;
	}
	value[0] = maxcount;
	value[1] = maxi;
	return value;
}
but that doesn't seem to help.
Reply
#2

pawn Код:
ReturnMax(&count, const string[], len)
{
    count = 0;
    new max_val = -1;
   
    for (new i; i != len; ++i)
    {
        if (string[i] > max_val)
        {
            max_val = string[i];
            count = 1;
        }
        else if (string[i] == max_val) ++count;
    }
    return max_val;
}
An example:
pawn Код:
test[0] = 44;
test[1] = 11;
test[2] = 44;

new
    count,
    value = ReturnMax(count, test, sizeof (test));
   
printf("%i %i", count, value);
It will print 2 (2 indexes with the highest number) and 44 (the highest number).
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
ReturnMax(&count, const string[], len)
{
    count = 0;
    new max_val = -1;
   
    for (new i; i != len; ++i)
    {
        if (string[i] > max_val)
        {
            max_val = string[i];
            count = 1;
        }
        else if (string[i] == max_val) ++count;
    }
    return max_val;
}
An example:
pawn Код:
test[0] = 44;
test[1] = 11;
test[2] = 44;

new
    count,
    value = ReturnMax(count, test, sizeof (test));
   
printf("%i %i", count, value);
It will print 2 (2 indexes with the highest number) and 44 (the highest number).
haha, Thanks, but at the end this wasn't what I needed.
I needed it to return ID of the highest.
Edited a bit.
Thanks anyways.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)