728x90
2056.์ฐ์์ผ ๋ฌ๋ ฅ - D1
1. 1์๋ถํฐ 12์๊น์ง 1์ผ๋ถํฐ ๋ฉฐ์น ๊น์ง ์ธ์ง days ๋ฐฐ์ด์ ์ ์ฅํด๋๋ค.
2. ๋ ์ง๋ฅผ String์ผ๋ก ์ ๋ ฅ๋ฐ๊ณ String์ substring์ ์ด์ฉํด month ๋ถ๋ถ๊ณผ day ๋ถ๋ถ์ ๋ถ๋ฆฌํ๋ค.
3. month๊ฐ 1~12์ฌ์ด์ธ์ง, day๊ฐ 1~๋ง์ง๋ง ๋ ์ง(30,31,28)์ ๋ง๊ฒ ๋์ด์๋์ง ํ์ธํ๋ค
4. ์ถ๋ ฅํ์๋๋ก ์ ์ฅํ๊ณ ์ถ๋ ฅํ๋ค.
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for(int test_case = 1; test_case <= T; test_case++)
{
String s = sc.next();
int month = Integer.valueOf(s.substring(4,6));
int day = Integer.valueOf(s.substring(6,8));
String result = "-1";
if( 1 <= month && month <= 12 && 1<=day && day <= days[month-1] ) {
result = String.format("%s/%s/%s", s.substring(0,4), s.substring(4,6), s.substring(6,8));
}
System.out.println("#" + test_case + " " + result);
}
}
}
๋ ๐ง
'SWEA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SWEA] 2043. ์๋์ ๋น๋ฐ๋ฒํธ (0) | 2022.05.18 |
---|---|
[SWEA] 2046. ์คํฌํ ์ฐ๊ธฐ (0) | 2022.05.18 |
[SWEA] 2047. ์ ๋ฌธ ํค๋๋ผ์ธ (0) | 2022.05.17 |
[SWEA] 2050. ์ํ๋ฒณ์ ์ซ์๋ก ๋ณํ (0) | 2022.05.17 |
[SWEA] 2058. ์๋ฆฟ์ ๋ํ๊ธฐ (0) | 2022.05.07 |
๋๊ธ