Wednesday, September 08, 2010

[UVa] 10107 - What is the Median

Algorithms used: Insertion Sort
I think with C++ maps this can be solved with a better runtime.


#include <stdio.h>
long int list[10050];
int main() {
long int IN, R, I;
int C=1;
list[0]=-9999;
while (scanf("%ld",&IN)!=EOF) {
for (I=C++ ; IN<list[I-1] ; I--) {
list[I]=list[I-1];
}
list[I] = IN;

if (C%2) {
R = (long int)(( list[(int)C/2] + list[(int)C/2 + 1] )/2);
} else {
R = (long int)list[(int)C/2];
}
printf("%ld\n",R);
}
return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...