https://www.acmicpc.net/problem/2884
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringTokenizer st = new StringTokenizer(str," ");
int H = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
if(M < 45) {
H--;
M = 60 - (45 - M);
if(H < 0) {
H = 23;
}
System.out.println(H + " " + M);
}
else {
System.out.println(H + " " + (M - 45));
}
}
}
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
fun main() = with(System.`in`.bufferedReader()){
val str = readLine()
val token = StringTokenizer(str," ")
var H = token.nextToken().toInt()
var M = token.nextToken().toInt()
if (M<45){
H--
M = 60-(45-M)
if(H < 0){
H = 23
}
println("${H} ${M}")
} else {
println("${H} ${M-45}")
}
}
BufferedReader는 Scanner 와 다르게 배열을 생성하지 않고 문자열을 그대로 읽어 들이기 때문에 속도가 빨라요.
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int H = sc.nextInt();
int M = sc.nextInt();
sc.close();
if(M<45){
H--;
M= 60-(45-M);
if(H<0){
H=23;
}
System.out.println(H + " " + M);
}
else {
System.out.println(H + " " + (M-45));
}
}
}
import java.util.Scanner
fun main() = with(Scanner(System.`in`)){
var H = nextInt()
var M = nextInt()
if (M<45){
H--
M = 60-(45-M)
if(H < 0){
H = 23
}
println("${H} ${M}")
} else {
println("${H} ${M-45}")
}
}
[백준] 2884번 : 알람 시계 - JAVA [자바]
[백준] 1000번 : A+B - JAVA [자바]
JAVA [자바] - 입력 뜯어보기 [Scanner, InputStream, BufferedReader]