[프로그래머스] 카펫

leejihun·2022년 11월 13일
0

알고리즘

목록 보기
34/50

https://school.programmers.co.kr/learn/courses/30/lessons/42842

#include <string>
#include <vector>
#include <cmath>

using namespace std;

vector<int> solution(int brown, int yellow)
{
    vector<int> answer;
    
    int iSize = brown+ yellow;
    
    for(int i=3; i<=sqrt(iSize); i++)
    {
           if (iSize % i == 0) 
           {
            int width = iSize / i;
               
            if (((width + i) * 2 - 4) == brown)
                {
                    answer.push_back(width);
                    answer.push_back(i);
                    break;
                }
           }
    }
    
        
    return answer;
    
}

갈색 격자의 수 brown, 노란색 격자의 수 yellow가 매개변수로 주어질 때 카펫의 가로, 세로 크기를 구분하고 (width + height) * 2 - 4) == brown 의 식을 세우는게 해결방법

profile
U+221E

0개의 댓글