time limit per test
1 second
memory limit per test
256 megabytes
input: standard input
output: standard output
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows ℎh hours and 𝑚m minutes, where 0≤ℎℎ<240≤hh<24 and 0≤𝑚𝑚<600≤mm<60. We use 24-hour time format!
Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows 00 hours and 00 minutes.
You have to answer 𝑡t independent test cases.
Input
The first line of the input contains one integer 𝑡t (1≤𝑡≤14391≤t≤1439) — the number of test cases.
The following 𝑡t lines describe test cases. The 𝑖i-th line contains the time as two integers ℎh and 𝑚m (0≤ℎ<240≤h<24, 0≤𝑚<600≤m<60). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: ℎ=0h=0 and 𝑚=0m=0. It is guaranteed that both ℎh and 𝑚m are given without leading zeros.
Output
For each test case, print the answer on it — the number of minutes before the New Year.
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public class Main {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n=Integer.parseInt(br.readLine()); //test case입력
int sum=0;
for(int i=0;i<n;i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int h=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
sum+=(23-h)*60;
sum+=60-m;
System.out.println(sum);
sum=0;
}
}
}
|
'Algorithms > Coding_Contest' 카테고리의 다른 글
[그래프 위상정렬] Topological Sort : Java (0) | 2021.07.20 |
---|---|
[NWERC 2006] Printer Queue [Java] (0) | 2020.07.25 |