1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 5 long long Median, arr[10010]; 6 7 8 int main() 9 { 10 int i, cur_index, count, isOdd; 11 count = 0; 12 while(scanf("%lld", &arr[0]) != EOF) // arr[0] is a monitor 13 { 14 count ++; // count: caculate numbers 15 cur_index = count; // cur_index initial value: count 16 for(i=1; i<count; i++) 17 { 18 if(arr[0] < arr[i]) 19 { 20 cur_index = i; 21 break; 22 } 23 } 24 25 for(i=count; i>cur_index; i--) // backword move to arr[count] 26 arr[i] = arr[i-1]; 27 28 arr[cur_index] = arr[0]; // whatever, this is must. 29 30 isOdd = count % 2; 31 if(isOdd) 32 Median = arr[count/2 + 1]; // odd 33 else Median = (arr[count/2 +1] + arr[count/2]) / 2; // even 34 35 cout << Median << endl; 36 } 37 return 0; 38 }
犯错:漏写 break; 语句
时间: 2024-10-12 22:12:59