문제를 이해하고 문제의 조건을 따라가는 것이 중요한 문제다.
카펫의 테두리 1줄은 갈색 나머지는 노란색으로 칠해져있다. 카펫의 노란색 부분의 개수와 갈색 부분의 개수가 주어질 때 카펫의 가로 세로 길이를 구하여라
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int brown, int yellow) {
vector<int> answer;
int ylow, ycol; //노란색 가로, 세로
int blow, bcol; //갈색 가로, 세로
int tmp=1;
while(1){
//노란색의 가로 크기를 하나씩 키우면서 확인한다.
ylow=tmp;
if(yellow%ylow!=0){
tmp++;
continue;
}
ycol=yellow/ylow;
blow=ylow+2;
bcol=ycol+2;
if(brown+4==2*(blow+bcol)){
break;
}
tmp++;
}
answer.push_back(bcol);
answer.push_back(blow);
return answer;
}