算法初步——two pointers A1029.Median(25)

 并没有用到双指针遍历

#include <bits/stdc++.h>
#include<math.h>
#include <string>
using namespace std;
const int N = 2000005;
long int temp[N];
int main(){
    int count = 0;
    int n,m;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",&temp[count]);
        count++;
    }
    scanf("%d",&m);
    for(int i=0;i<m;++i){
        scanf("%d",&temp[count]);
        count++;
    }
    sort(temp,temp+count);
    int left = 0,right = count-1;
    /*for(int i=0;i<count;++i){
        if(left == right || left+1 == right){
            
        }
    }*/
    if(count % 2 ==0){
        cout<<temp[(count/2)-1];
    }else{
        cout<<temp[(count/2)];
    }
    system("pause");
    return 0;
} 
原文地址:https://www.cnblogs.com/JasonPeng1/p/12193367.html