SWEA_2056) 연월일 달력
SWEA
# D1
2056) 연월일 달력 (19.10.02)
문제 링크 (SW Expert Academy)
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
|
import java.io.*;
public class Solution {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String ymd;
int t = Integer.parseInt(br.readLine());
for(int p=1;p<=t;p++) {
ymd = br.readLine();
String year;
String month;
String day;
year = ymd.substring(0, 4);
month = ymd.substring(4, 6);
day = ymd.substring(6, 8);
int ans = 0;
int m = Integer.parseInt(month);
int d = Integer.parseInt(day);
if(m>12 || m<1) ans = -1;
else if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) {
if(d>31 || d<1) ans = -1;
}
else if(m==4 || m==6 || m==9 || m==11) {
if(d>30 || d<1) ans = -1;
}
else if(m==2) {
if(d>28 || d<1) ans = -1;
}
if(ans==-1) bw.write("#" + p + " " + ans +"\n");
else bw.write("#" + p + " " + year+ "/" + month +"/" + day+"\n");
}
bw.flush();
bw.close();
}
}
| cs |
댓글
댓글 쓰기