Printf 출력 모음

Loopy·2024년 1월 13일
0

코테 문제들

목록 보기
85/113

0101 출력 -> %04d

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Solution {
	public static void main(String[] args) throws Exception {

		System.setIn(new FileInputStream("./sw2056/input2056.txt"));

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());

		int treuDay[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

		for (int test_case = 1; test_case <= T; test_case++) {
			int all = Integer.parseInt(br.readLine());
			int year = all / 10000;
			int month = (all - year * 10000) / 100;
			int day = all % 100;

			if (month < 1 || month > 12 || day < 1 || day > treuDay[month - 1]) {
				System.out.printf("#%d -1\n", test_case);
			} else {
				System.out.printf("#%d %04d/%02d/%02d\n", 
                test_case, year, month, day);
			}

		}

	}
}
profile
잔망루피의 알쓸코딩

0개의 댓글