Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b4f57b6

Browse files
Add files via upload
2023年07月25日
1 parent ceeaedf commit b4f57b6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package Programmers;
2+
3+
import java.util.Scanner;
4+
5+
public class No42842 {
6+
7+
public static int[] solution(int brown, int yellow) {
8+
int totalTiles = brown + yellow;
9+
10+
// 가로 길이를 3부터 시작해야 노란색 타일을 감쌀 수 있음.
11+
for (int width = 3; width <= 5000; width++) {
12+
if (totalTiles % width == 0) { // 전체 타일 수가 가로 길이로 나누어떨어지면, 세로 길이를 구할 수 있다.
13+
int height = totalTiles / width;
14+
15+
// 세로 길이가 가로 길이보다 작거나 같고, 입력한 노란색 격자 수가 맞는 경우에 결과 배열을 구성하여 반환.
16+
if (height <= width && (width - 2) * (height - 2) == yellow) {
17+
return new int[]{width, height};
18+
}
19+
}
20+
}
21+
return new int[]{0, 0}; // 예외처리 0으로 반환하거나 에러 처리
22+
}
23+
24+
public static void main(String[] args) {
25+
Scanner sc = new Scanner(System.in);
26+
int brown = sc.nextInt();
27+
int yellow = sc.nextInt();
28+
int[] result = solution(brown, yellow);
29+
30+
System.out.println("카펫의 크기: [" + result[0] + ", " + result[1] + "]");
31+
}
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /