๐ก Info
- ๋์ด๋: ๐ฅBronze II
- ์๊ฐ ์ ํ: 1์ด
- ๋ฉ๋ชจ๋ฆฌ ์ ํ: 256MB
๋ฐฑ์ค ๋งํฌ: https://www.acmicpc.net/problem/18406
ํ์ด ๋งํฌ(GitHub): hayannn/CodingTest_Java/#18406. ๋ญํค ์คํธ๋ ์ดํธ
1 + 2 + 3
, ์ค๋ฅธ์ชฝ ๋ถ๋ถ์ ๊ฐ ์๋ฆฟ์์ ํฉ์ 4 + 0 + 2
์ด๋ฏ๋ก ๋ ํฉ์ด 6์ผ๋ก ๋์ผํ์ฌ ๋ญํค ์คํธ๋ ์ดํธ ์ฌ์ฉ ๊ฐ๋ฅ123402
7755
LUCKY
READY
์ค์ ํ์ด ์๊ฐ : 17๋ถ
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//1. N ์
๋ ฅ๋ฐ๊ธฐ
int N = sc.nextInt();
int[] arr = new int[N];
for(int i=0; i<N; i++){
arr[i] = sc.nextInt();
}
//2. N์ ์ ๋ฐ์ผ๋ก ์๋ฅด๊ธฐ
int mid = arr.length / 2;
int[] first = Arrays.copyOfRange(arr, 0, mid);
int[] end = Arrays.copyOfRange(arr, mid, arr.length);
//3. ๊ฐ ํฉ ๊ตฌํ๊ธฐ
int firstSum = Arrays.stream(first).sum();
int endSum = Arrays.stream(end).sum();
//4. ๋ ํฉ ๋น๊ตํ๊ธฐ
// - ๋ง์ฝ, ๋ ํฉ์ด ์ผ์นํ๋ค๋ฉด LUCKY ์ถ๋ ฅ
// - ๋ ํฉ์ด ์ผ์นํ์ง ์๋๋ค๋ฉด READY ์ถ๋ ฅ
if(firstSum == endSum){
System.out.println("LUCKY");
} else {
System.out.println("READY");
}
}
}
N์ ์ ๋ ฅ๋ฐ์ ๊ฒฝ์ฐ, String์ผ๋ก ๋ฐ์์ผ ํจ!
//1. N ์
๋ ฅ๋ฐ๊ธฐ
String input = sc.nextLine().trim();
int N = input.length();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = input.charAt(i) - '0';
}
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//1. N ์
๋ ฅ๋ฐ๊ธฐ
String input = sc.nextLine().trim();
int N = input.length();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = input.charAt(i) - '0';
}
//2. N์ ์ ๋ฐ์ผ๋ก ์๋ฅด๊ธฐ
int mid = N / 2;
int[] first = Arrays.copyOfRange(arr, 0, mid);
int[] end = Arrays.copyOfRange(arr, mid, arr.length);
//3. ๊ฐ ํฉ ๊ตฌํ๊ธฐ
int firstSum = Arrays.stream(first).sum();
int endSum = Arrays.stream(end).sum();
//4. ๋ ํฉ ๋น๊ตํ๊ธฐ
// - ๋ง์ฝ, ๋ ํฉ์ด ์ผ์นํ๋ค๋ฉด LUCKY ์ถ๋ ฅ
// - ๋ ํฉ์ด ์ผ์นํ์ง ์๋๋ค๋ฉด READY ์ถ๋ ฅ
if(firstSum == endSum){
System.out.println("LUCKY");
} else {
System.out.println("READY");
}
}
}