We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ceeaedf commit b4f57b6Copy full SHA for b4f57b6
AlgorithmDrills/src/Programmers/No42842.java
@@ -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
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments