ps/브루트 포스
2309 일곱 난쟁이
private K
2021. 8. 21. 14:16
일곱 난쟁이 (2309)
풀이코드
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
// 2309 일곱 난쟁이
const int MAX = 100;
vector<int> hobits;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int sum = 0;
for(int i = 0; i < 9; i++) {
int tmp;
cin >> tmp;
hobits.push_back(tmp);
sum += hobits[i];
}
sort(hobits.begin(), hobits.end());
for(int i = 0; i < 9; i++){
for(int j = i + 1; j < 9; j++){
if(sum - hobits[i] - hobits[j] == 100) {
for(int k = 0; k < 9; k++){
if(i == k || j == k) continue;
cout << hobits[k] << "\n";
}
return 0;
}
}
}
}
해설
적용한 레시피 / 방법론 + 접근법
풀이
아쉬웠던 부분 / 오답 원인 / 개선해야 할 점
return 0 을 적절히 써주지 않아서 한 번 틀렸다.
반응형