-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy path10107.cpp
executable file
·56 lines (49 loc) · 1.07 KB
/
10107.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Problem: What is Median? UVa 10107
Programmer: Md. Mahmud Ahsan
Compiled: Visual C++ 6.0
Date: 11-12-04
*/
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
typedef long lint;
// prototypes
void insertionSort(lint array[], lint size);
//==========================================
int main(){
//ifstream fin("input.in");
//cin = fin;
lint i = 0;
lint sum, med;
lint array[10005];
while (cin >> array[i]&& !cin.eof()){
insertionSort(array, i+1);
if (i % 2 == 1) {
// if i is even as array begins 0 so here checking system differ
med = i / 2;
sum = array[med] + array[med + 1];
sum = sum / 2;
cout << sum << endl;
}
else{
med = i / 2;
cout << array[med] << endl;
}
++i;
}
return 0;
}
//=========================================
void insertionSort(lint array[], lint size){
int i, j, key;
for (j = 1; j < size; j++){
key = array[j];
i = j - 1;
while (i >= 0 && array[i] > key){
array[i + 1] = array[i];
i = i - 1;
}
array[i + 1] = key;
}
}