웅재의 코딩세상
[프로그래머스] 홀수 vs 짝수 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> num_list) {
int answer[2];
for(int i=0; i<num_list.size(); i++){
if((i+1)%2 == 0) answer[0] += num_list[i];
else answer[1] += num_list[i];
}
return answer[0] < answer[1] ? answer[1] : answer[0];
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 간단한 논리 연산 (0) | 2024.01.30 |
---|---|
[프로그래머스] 0 떼기 (1) | 2024.01.29 |
[프로그래머스] A 강조하기 (0) | 2024.01.29 |
[프로그래머스] 글자 이어 붙여 문자열 만들기 (0) | 2024.01.29 |
[프로그래머스] 길이에 따른 연산 (0) | 2024.01.29 |