문제 링크입니다: https://www.acmicpc.net/problem/3058
3058번: 짝수를 찾아라
입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터는 한 줄로 구성되어 있고, 7개의 자연수가 공백으로 구분되
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
const int MAX = 7; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int T; | |
cin >> T; | |
for (int t = 0; t < T; t++) | |
{ | |
vector<int> v(MAX); | |
for (int i = 0; i < MAX; i++) | |
{ | |
cin >> v[i]; | |
} | |
sort(v.begin(), v.end()); | |
int sum = 0; | |
int minEven = -1; | |
for (int i = 0; i <MAX; i++) | |
{ | |
if (v[i] % 2) | |
{ | |
continue; | |
} | |
if (minEven == -1) | |
{ | |
minEven = v[i]; | |
} | |
sum += v[i]; | |
} | |
cout << sum << " " << minEven << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 3029번 경고 (0) | 2021.05.14 |
---|---|
백준 3034번 앵그리 창영 (0) | 2021.05.14 |
백준 6757번 팰린드롬 진법 (2) | 2021.05.13 |
백준 2997번 네 번째 수 (4) | 2021.05.12 |
백준 2991번 사나운 개 (0) | 2021.05.11 |