SWEA 2063 중간값 찾기

1 개요[ | ]

SWEA 2063 중간값 찾기

2 C++[ | ]

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, temp;
    cin >> N;
    vector<int> a;
    for(int i=0; i<N; i++) {
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(), a.end());
    cout << a[N/2] << endl;
}

3 Java[ | ]

import java.util.Scanner;
import java.util.Arrays;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int nums[] = new int[N];
        for(int i=0; i<N; i++) nums[i] = sc.nextInt();
        Arrays.sort(nums);
        System.out.println( nums[(N-1)/2] );
    }
}

4 Python[ | ]

#kcy
k = int(input())
lst = list(map(int, input().split()))
k = int((k-1)/2)
lst.sort()
print(lst[k])
T = int(input())
lst = list(map(int, input().split()))
lst.sort()
print( lst[int((T-1)/2)] )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}