본문으로 바로가기

2309 일곱 난쟁이

category ps/브루트 포스 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 을 적절히 써주지 않아서 한 번 틀렸다.

반응형

'ps > 브루트 포스' 카테고리의 다른 글

리모컨 1107  (0) 2021.08.22
3085 사탕 게임  (0) 2021.08.21
11726  (0) 2021.07.10
1476  (0) 2021.07.10
[algospot] 게임판 덮기 BOARDCOVER  (0) 2021.06.13