프로그래머스
[C++][프로그래머스][Lv2] 42842. 카펫
youcheachae
2024. 7. 18. 16:52
https://school.programmers.co.kr/learn/courses/30/lessons/42842
[C++][프로그래머스][Lv2] 42842. 카펫
❗
노랑색의 가로가 w, 세로가 h일 때
가능한 갈색의 타일 갯수는 ( 가로 + 2 ) x 2 + (세로 + 세로 ) 이다.
✅풀이방법
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int b, int y) {
vector<int> answer;
// yellow 기준으로 공약수 구하기
for (int i = 1; i <= y; i++)
{
// 나머지가 0이면 -> 나눠짐
if (y % i == 0)
{
int tempWidth = y / i;
int tempHeight = y / tempWidth;
// 가능한 갈색의 갯수
int broundTile = ( tempWidth + 2) * 2 + tempHeight * 2;
// 가능한 갈색이랑 같으면 ?
if(b == broundTile)
{
answer.push_back( tempWidth + 2);
answer.push_back( tempHeight + 2);
break;
}
}
}
return answer;
}
https://github.com/kimYouChae/C-Programmers
GitHub - kimYouChae/C-Programmers
Contribute to kimYouChae/C-Programmers development by creating an account on GitHub.
github.com