"SWEA 2056 연월일 달력"의 두 판 사이의 차이

19번째 줄: 19번째 줄:
         Scanner sc = new Scanner(System.in);
         Scanner sc = new Scanner(System.in);
         int T = sc.nextInt();
         int T = sc.nextInt();
         for(int t=1; t<=T; t++) {
         for(int tc=1; tc<=T; tc++) {
             String s = sc.next();
             String s = sc.next();
             int month = Integer.valueOf(s.substring(4,6));
             int month = Integer.valueOf(s.substring(4,6));
27번째 줄: 27번째 줄:
                 res = String.format("%s/%s/%s", s.substring(0,4), s.substring(4,6), s.substring(6,8));
                 res = String.format("%s/%s/%s", s.substring(0,4), s.substring(4,6), s.substring(6,8));
             }
             }
             System.out.format("#%d %s\n", t, res);
             System.out.format("#%d %s\n", tc, res);
         }
         }
     }
     }
}
}
</source>
</source>

2019년 1월 14일 (월) 19:57 판

1 개요

SWEA 2056 연월일 달력
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 1-1

2 C++

3 Java

import java.util.Scanner;
class Solution {
    public static void main(String args[]) {
        int daysOfMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31}; 
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int tc=1; tc<=T; tc++) {
            String s = sc.next();
            int month = Integer.valueOf(s.substring(4,6));
            int day = Integer.valueOf(s.substring(6,8));
            String res = "-1";
            if( 1<=month && month<=12 && 1<=day && day<=daysOfMonth[month-1] ) {
                res = String.format("%s/%s/%s", s.substring(0,4), s.substring(4,6), s.substring(6,8));
            }
            System.out.format("#%d %s\n", tc, res);
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}