九度oj1004Median

#include<iostream>
using namespace std;
#include<algorithm>
#define maxn 2000010
int a[maxn];
 
int main()
{
    long int N1,N2;
 
    while(cin >> N1)
    {
        for(int i = 0; i < N1; i++)
            cin >> a[i];
        cin >> N2;
        for(int j = N1; j < N2+N1; j++)
            cin >> a[j];  
        sort(a,a+N1+N2);
        cout << a[(N1+N2-1)/2] << "\n";
    }
 
    return 0;
}
/**************************************************************
    Problem: 1004
    User: true14fans
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:9332 kb
****************************************************************/
纔看完deitel的書前五章,這是個簡便的方法。學了string類寫個V5的回來
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章