728x90
๋ฐ์ํ
๋ฐฑ์ค 2๋จ๊ณ ์กฐ๊ฑด๋ฌธ ํ์ด ๋ชจ์.
์ค๋ ์ ๋ฐ๋ก ํฌ์คํ ์ฌ๋ ค๋์๋ค.
๐ 2884 ์๋์๊ณ (196ms)
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int H = scanner.nextInt();
int M = scanner.nextInt();
if ( H > 0 ) {
if ( M >= 45) {
M = M - 45;
System.out.println(H +" "+ M);
} else if ( M < 45) {
H = H - 1;
M = M + 15;
System.out.println(H +" "+ M);
}
} else if ( H == 0 ) {
if ( M >= 45) {
M = M - 45;
System.out.println(H +" "+ M);
} else if ( M < 45) {
H = 23;
M = M + 15;
System.out.println(H +" "+ M);
}
}
}
}
๐ 2525 ์ค๋ธ์๊ณ (148ms)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public 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());
int h = (B + C)/60;
int m = (B + C)%60;
int fh = A + h;
if (fh > 23){
System.out.println(fh-24 +" "+ m);
} else {
System.out.println(fh+" "+ m);
}
}
}
๐ญํ์ด
60๋ถ == 1์๊ฐ
๊ทธ๋ฌ๋ฉด ๋ถ(B,C)์ ๋ชจ๋ ๋ํด์ 60๋ถ์ผ๋ก ๋๋ ๋ชซ๊ณผ ๋๋จธ์ง๋ฅผ ์ด์ฉํ์
๋ง์ฝ์ 23์๋ฅผ ๋์ด๋ฒ๋ฆฌ๋ฉด 0์ผ๋ก ๋ณ๊ฒฝํ์ (24๋นผ๊ธฐ)
๐ 2480 ์ฃผ์ฌ์ ์ธ๊ฐ (104ms)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public 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 n1 = Integer.parseInt(st.nextToken());
int n2 = Integer.parseInt(st.nextToken());
int n3 = Integer.parseInt(st.nextToken());
int max = n1;
if (n1 == n2 && n1 == n3) {
System.out.println(10000 + n1*1000);
} else if (n1 == n2 || n1 == n3) {
System.out.println(1000 + n1*100);
} else if (n2 == n3) {
System.out.println(1000 + n2*100);
} else {
if(max <= n2){
max = n2;
if(max <= n3){
max = n3;
}
} else {
if(max <= n3){
max = n3;
}
}
System.out.println(max*100);
}
}
}
๐ญํ์ด
์ด๋ฏธ ์์ if์์ ๊ฑธ๋ฌ์ง ์กฐ๊ฑด์ else if์ ์์ ์ด๋ ๋๋ค.
n2 == n3 ์กฐ๊ฑด์ ์๋ฃ์ด๋ ๋๋ ์ด์ .
728x90
๋ฐ์ํ
'๐ป ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค/Java] 10951 A+B - 4 : EOF๋? (0) | 2025.01.17 |
---|---|
[๋ฐฑ์ค/Java] 10950 A+B -3 : ์ ๋ ฅ ์คํธ๋ฆผ ์ค๋ณต์ผ๋ก ์ธํ ๋ฐํ์ ์๋ฌ (0) | 2025.01.17 |
[๋ฐฑ์ค/Java] 2753 ์ค๋ - ๋จ์ถํ๊ฐ short circuit (0) | 2025.01.17 |
์๋ฐ ์ ๋ ฅ์ ๊ดํ ๊ณ ์ฐฐ (Scanner, BufferedReader) (0) | 2025.01.14 |
[๋ฐฑ์ค/Java] 10172 ๊ฐ : ์๋ฐ์์ " ์ถ๋ ฅ (0) | 2025.01.14 |