๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SWEA

[SWEA] 2056. ์—ฐ์›”์ผ ๋‹ฌ๋ ฅ

by JulesJ 2022. 5. 7.
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);
		}
	}
}

 

๋ ๐Ÿง

๋Œ“๊ธ€