๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm๐Ÿฐ/๋ฐฑ์ค€

[๋ฐฑ์ค€] 10818 ์ตœ์†Œ, ์ตœ๋Œ€

by Jouureee 2021. 2. 16.

๋ฌธ์ œ : 

www.acmicpc.net/search#q=10818&c=Problems

 

๊ฒ€์ƒ‰

 

www.acmicpc.net

 

๋ถ„์„ :

์ด ๋ฌธ์ œ๋Š” ๋ชปํ‘ผ ๋ฌธ์ œ์— ์žˆ๊ธธ๋ž˜ ํด๋ฆญ ํ•ด๋ณด๋‹ˆ ๋น„๊ต์  ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ๋ผ์„œ ํ’€์—ˆ๋‹ค. 1๋…„์ „ ๋ฌธ์ œ๋ผ๋‹ˆ ์„ธ์›”์ด ๋น ๋ฅด๊ตฌ๋‚˜ 

* ๋ฐ˜๋ก€๋กœ 

1

10 

์ผ€์ด์Šค์™€ 

10 10

์ผ€์ด์Šค๊ฐ€ ์žˆ์œผ๋‹ˆ ์ž˜ ์ƒ๊ฐํ•ด๋ณด๊ธธ ๋ฐ”๋ž€๋‹ค.

์ฒ˜์Œ์—๋Š” for๋ฌธ ํ•˜๋‚˜์— input ๊ฐ’ ๋„ฃ๊ณ  ๋ฐ”๋กœ ๋น„๊ต ํ•˜๋ ค ํ–ˆ๋Š”๋ฐ ์œ„ ๋‘ ์ผ€์ด์Šค ๋•Œ๋ฌธ์— ๋ถ„๋ฆฌํ•ด์„œ ๋‹ด์•„์คฌ๋‹ค. 

 

C++ ์ฝ”๋“œ :

//
//  10818_min_max.cpp
//  SOMA๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป
//
//  Created by JoSoJeong on 2021/02/12.
//

#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, max, min;
    max = -1000000;
    min = 1000000;
    cin >> n;
    int v[n];
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    max = v[0];
    min = v[1];
    for(int i = 0; i < n; i++){
        if(v[i] > max){
            max = v[i];
        }
        if(v[i] < min){
            min = v[i];
        }
    }
        
    cout << min << " " << max << endl;
    
    return 0;
}

 

๋Œ“๊ธ€