"SWEA 2063 중간값 찾기"의 두 판 사이의 차이

9번째 줄: 9번째 줄:
==C++==
==C++==
<source lang='cpp'>
<source lang='cpp'>
#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;
}
</source>
</source>



2019년 1월 14일 (월) 19:55 판

1 개요

SWEA 2063 중간값 찾기
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 1-1

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] );
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}