-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathP115.java
46 lines (35 loc) · 1.19 KB
/
P115.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
115. Calendar
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
First year of new millenium is gone away. In commemoration of it write a program
that finds the name of the day of the week for any date in 2001.
Input
Input is a line with two positive integer numbers N and M, where N is a day number
in month M. N and M is not more than 100.
Output
Write current number of the day of the week for given date (Monday ¨C number 1, ¡ ,
Sunday ¨C number 7) or phrase ¡°Impossible¡± if such date does not exist.
Sample Input
21 10
Sample Output
7
*/
import java.util.*;
public class P115 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
Calendar calendar = new GregorianCalendar(2001, m - 1, n);
if(calendar.get(Calendar.YEAR) != 2001 ||
calendar.get(Calendar.MONTH) != m - 1 ||
calendar.get(Calendar.DAY_OF_MONTH) != n)
System.out.println("Impossible");
else {
int res = calendar.get(Calendar.DAY_OF_WEEK);
res = res == 1 ? 7 : res - 1;
System.out.println(res);
}
}
}