๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜

[C++/SWEA] 1206. [S/W ๋ฌธ์ œํ•ด๊ฒฐ ๊ธฐ๋ณธ] 1์ผ์ฐจ - View (D3)

728x90

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV134DPqAA8CFAYh&categoryId=AV134DPqAA8CFAYh&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=CCPP&select-1=3&pageSize=10&pageIndex=1

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

์ตœ๋Œ“๊ฐ’ ์•„์ด๋””์–ด

 

๋‚˜์˜ ํ’€์ด

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;
    int height;
//    freopen("sample_input.txt", "r", stdin);
    for(test_case = 1; test_case <= 10; ++test_case)
	{
        int answer = 0;
        vector<int> h;
        cin >> T;
        for (int i = 0; i < T; ++i){
            cin >> height;
            h.push_back(height);
        }
        for (int i = 2; i < T-2; ++i){
            if(h[i]==0)
                continue;
            if(h[i]>h[i-1] && h[i]>h[i+1]){
                if(h[i]>h[i-2] && h[i]>h[i+2]){
                    int m = max({h[i - 1], h[i - 2], h[i + 1], h[i + 2]});
                    answer += (h[i] - m);
                }
            }
        }
        cout << "#" << test_case << " " << answer << "\n";
    }
    return 0;//์ •์ƒ์ข…๋ฃŒ์‹œ ๋ฐ˜๋“œ์‹œ 0์„ ๋ฆฌํ„ดํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
}
728x90