인상 깊었던 문제 1
[JAVA] 백준 2480번 문제
풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
if(x==y && y==z) { // 세 개의 주사위가 모두 같은 경우
System.out.println(10000+(x*1000));
} else if(x==y || y==x || x==z || z==y) { // 두 개의 주사위가 같은 경우
if(x==y || x==z) { // x가 y 또는 z와 같은 경우
System.out.println(1000 + (x*100));
} else if(z==y) { // z가 y와 같은 경우
System.out.println(1000 + (z*100));
}
} else { // x, y, z가 다 다를 경우 세 개를 비교해 최대값을 정한다.
if(x>y) {
if(x>z) {
System.out.println(x*100);
} else {
System.out.println(z*100);
}
} else if (y>z) {
System.out.println(y*100);
} else {
System.out.println(z*100);
}
}
}
}
▶ x, y, z 세 개의 주사위 값을 받는다.
▶ 규칙에 따라 주사위 값을 비교하는 로직을 짠다.
▶ 생각해보니 맨 마지막에 최대값 구할 때는 배열에 넣어서 돌리면 더 간단한 로직이 나오지 않았을까 싶음
int[] arr = new int{x, y, z};
int max = arr[0]
for(int i = 1; i<arr.length; i++){
if(max<arr[i]){
max = arr[i]
}
}
System.out.println(max*100)
인상 깊었던 문제 2
[JAVA] 백준 10950번 문제
풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 1; i <= T; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a+b);
}
sc.close();
}
}
▶ 처음으로 테스트케이스라는 단어가 나온 문제. 이게 뭔 소린가 했다.
▶ 입력 예제를 아무리 들여다보아도 뭔지 알 수 없었는데, 알고 보니 맨 위 5는 a, b를 몇 번 입력받을 지 정하는 거였다. 핳
▶ 그냥 입력 받는 대로 a와 b를 더하는 쉬운 문제
어제보다 푼 문제수는 적음
오늘 시험본다고 해서 열심히 달린 거라,
아마 앞으로 더 하루에 푸는 문제가 적어질 예정.