[JAVA] 백준 2단계
2024. 9. 3. 19:48ㆍ코딩 테스트(Coding Test)/백준
1330 두 수 비교하기
나의 답) 100ms
import java.io.*;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
String ans = a > b ? ">" : (b > a ? "<" : "==");
System.out.print(ans);
}
}
9498 시험 성적
나의 답1) 104ms
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int score = Integer.parseInt(br.readLine());
char grade = score >= 90 ? 'A' : (score >= 80 ? 'B' : (score >= 70 ? 'C' : (score >= 60 ? 'D' : 'F')));
System.out.print(grade);
}
}
나의 답2) 100ms
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int score = Integer.parseInt(br.readLine());
char grade;
if (score >= 90) grade = 'A';
else if (score >= 80) grade = 'B';
else if (score >= 70) grade = 'C';
else if (score >= 60) grade = 'D';
else grade = 'F';
System.out.print(grade);
}
}
2753 윤년
나의 답) 100ms
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int year = Integer.parseInt(br.readLine());
int res = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0) ? 1 : 0);
System.out.print(res);
}
}
다른 사람의 답) 104ms
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0) {
System.out.print("1");
} else {
System.out.print("0");
}
}
}
14681 사분면 고르기
나의 정답) 96ms
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int res;
int x = Integer.parseInt(br.readLine());
int y = Integer.parseInt(br.readLine());
if (x > 0 && y > 0) res = 1;
else if (x < 0 && y > 0) res = 2;
else if (x < 0 && y < 0) res = 3;
else res = 4;
System.out.print(res);
}
}
2884 알람 시계
나의 정답) 108ms
import java.io.*;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int H = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
if (M >= 45) {
M -= 45;
} else {
M += 15;
if (H >= 1) H -= 1;
else H += 23;
}
System.out.printf("%d %d", H, M);
}
}
2525 오븐 시계
나의 정답) 104ms
import java.io.*;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(br.readLine());
B += C;
A += B / 60;
B = B % 60;
A %= 24;
System.out.printf("%d %d", A, B);
}
}
2480 주사위 세개
나의 답) 96ms
import java.io.*;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int res;
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int z = Integer.parseInt(st.nextToken());
if (x == y && y == z) res = 10000 + x * 1000;
else if (x == y || y == z || z == x) {
if (x == y) res = 1000 + x * 100;
else res = 1000 + z * 100;
} else {
if (x > y && x > z) res = x * 100;
else if (y > x && y > z) res = y * 100;
else res = z * 100;
}
System.out.print(res);
}
}
'코딩 테스트(Coding Test) > 백준' 카테고리의 다른 글
[JAVA] 백준 4단계 (0) | 2024.09.05 |
---|---|
[JAVA] 백준 3단계 (0) | 2024.09.04 |
[JAVA] 백준 1단계 (0) | 2024.09.03 |
[Python] 윤년 (0) | 2024.07.17 |
[Python] 시험 성적 (0) | 2024.07.17 |