C++/programmers 코딩테스트(level 2) C++

[C/C++] programmers Level 2 카펫

CE : 하랑 2023. 10. 8. 20:18

 

 

 

 

 

코드

 

#include <vector>

using namespace std;

vector<int> solution(int brown, int yellow) {
    vector<int> answer;
    
    int area=brown+yellow;
    int h=3; // 세로가 3이상이어야 중앙에 노란색을 칠함
    
    while(true){
        int w=area/h; // 가로
        
        if((w-2)*(h-2)==yellow){ // yellow = 가로-2 * 세로-2
            answer.push_back(w);
            answer.push_back(h);
            break;
        }
        
        h++;
    }
    
    return answer;
}