scone-lemon

[SWEA D1] 자바 깔짝 본문

ALGORITHM/SWEA

[SWEA D1] 자바 깔짝

lemon-scone 2023. 3. 27. 17:37

싸피 수료 이후, 그리고 은행에 취업 준비를 할 즈음부터 코딩을 아예 놓았다가,

약 10개월만에 다시 시작했다.

 

회사에서 여유로울 때마다 온라인 IDE로 SWEA D1을 조금씩 풀었다.

처음에는 임포트 하는 법이나 인풋받는 법, 심지어 클래스 선언하는 법마저 까먹어서 당황스러웠다.

 

그나마 다행스러웠던 점은, 머리로는 다 잊어버린 줄 알았던 부분들을,

손까락이 아직까지 기억하고 있어서, 가까스로 다시 자바 초심자의 상태에 도달할 수 있었다.

 

https://swexpertacademy.com/main/code/problem/problemList.do?problemLevel=1&contestProbId=&categoryId=&categoryType=&problemTitle=&orderBy=PASS_RATE&selectCodeLang=JAVA&select-1=&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

// import java.util.*;
// import java.io.*;

/** 2047. 신문 헤드라인
*
*
*
*
*/

// Solution 1 : 내장 함수 이용 with Scanner
// class Main {
//   public static void main(String[] args) {
//     Scanner sc = new Scanner(System.in);
//     String str = sc.nextLine();
//     System.out.println(str.toUpperCase());
//     sc.close();
//   }
// }

// Solution 2 : 내장 함수 이용 with BufferedReader
// class Main {
//   public static void main(String[] args) throws IOException {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();
//     String str = br.readLine();
//     sb.append(str.toUpperCase());
//     System.out.println(sb.toString());
//   }
// }

// BufferedReader vs Scanner
// BufferedWriter vs StringBuilder
// Why use InputStreamReader?

// class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();
//     String str = br.readLine();
//     sb.append(str.toUpperCase());
//     System.out.println(sb.toString());
//   }
// }

// Solution 3 : 내장 함수 이용 X with BufferedReader
// class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();
//     String str = br.readLine();
//     char[] arr = str.toCharArray();
//     for (int i = 0; i < arr.length; i++) {
//       if (arr[i] >= 97) {
//         arr[i] = (char) (arr[i] - 32); // (char) 을 써주지 않을 때에는 error
//       }
//     }
//     sb.append(arr);
//     System.out.println(sb.toString());
//   }
// }

// BufferedReader vs Scanner
// BufferedWriter vs StringBuilder
// BufferedReader 선언 시 InputStreamReader를 선언하는 이유
// char -+에서 (char) 이 필요한 이유
// ascii : 소문자(65~90) 대문자(97~122) 기억하자 => 97-32 기억

// class Main {
//   public static void main(String[] args) throws Exception{
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();
//     String str = br.readLine();
//     char[] arr = str.toCharArray();
//     for(int i = 0; i < arr.length; i++){
//       if(arr[i] >=97) arr[i] = (char) (arr[i] - 32);
//       sb.append(arr[i]);
//     }
//     System.out.println(sb.toString());
//   }
// }

/** 1938. 아주 간단한 계산기 
*
*
*
*
*/

// Solution 1 : Scanner 사용
// class Main {
//   public static void main(String[] args) throws Exception {
//     Scanner sc = new Scanner(System.in);

//     int N = sc.nextInt();
//     int M = sc.nextInt();

//     System.out.println(N+M);
//     System.out.println(N-M);
//     System.out.println(N*M);
//     System.out.println(N/M);

//    sc.close();

//   }
// }

// Solution : BufferedReader, StringTokenizer 사용
// class Main {
//   public static void main(String[] args) throws Exception {

//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringTokenizer st = new StringTokenizer(br.readLine(), " ");
//     StringBuilder sb = new StringBuilder();

//     int N = Integer.parseInt(st.nextToken());
//     int M = Integer.parseInt(st.nextToken());

//     sb.append(N+M).append("\n");
//     sb.append(N-M).append("\n");
//     sb.append(N*M).append("\n");
//     sb.append(N/M).append("\n");

//     System.out.println(sb.toString());
//   }
// }

/** 2046. 스탬프 찍기
  *
  *
  *
  *
  */

// public class Main {
//   public static void main(String[] args) {
//     // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     // StringBuilder sb = new StringBuilder();
//     // int n = Integer.parseInt(br.readLine);

//     Scanner sc = new Scanner(System.in);
//     int n = sc.nextInt();
//     for(int i=0; i<n; i++){
//       // sb.append("#");
//       System.out.print("#");
//     }
//     sc.close();
//     // System.out.println(sb.toString());
//   }
// }

/** 2043. 서랍의 비밀번호
  *
  *
  *
  *
  */

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();

//     String str = br.readLine();
//     StringTokenizer st = new StringTokenizer(str, " ");
//     int n = Integer.parseInt(st.nextToken());
//     int m = Integer.parseInt(st.nextToken());

//     int count = 0;
//     for(int i = m; i <=n; i++){
//       count++;
//     }
//     sb.append(count);
//     System.out.println(sb.toString());
//   }
// }

/** 2025. N줄덧셈
  *
  *
  *
  *
  */

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();
//     int n = Integer.parseInt(br.readLine());

//     int sum = 0;
//     for(int i=n; i>=0; i--){
//       sum = sum + i;
//     }

//     sb.append(sum);
//     System.out.println(sb.toString());
//   }
// }

/** 2058. 자릿수 더하기
  *
  *
  *
  *
  */

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();

//     char[] arr = br.readLine().toCharArray();

//     int sum = 0;
//     for(int i = 0; i< arr.length; i++){
//       sum = sum + arr[i] - '0';
//     }
//     sb.append(sum);
//     System.out.println(sb.toString());
//   }
// }

/** 1936. 1대1 가위바위보
  *
  *
  *
  *
  */

// 가위 1 / 바위 2 / 보 3
// 1 < 2, 1 > 3
// 2 > 1, 2 < 3
// 3 < 1, 3 > 2
// result : 1 < 2, 3 < 1, 2 < 3

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringTokenizer st;
//     StringBuilder sb = new StringBuilder();

//     st = new StringTokenizer(br.readLine(), " ");
//     int n = Integer.parseInt(st.nextToken());
//     int m = Integer.parseInt(st.nextToken());

//     // System.out.println(n);
//     // System.out.println(m);

//   }
// }

/** 2027. 대각선 출력하기
  *
  *
  *
  *
  */

// public class Main {
//   public static void main(String[] args) throws Exception {
//     for(int i = 0; i < 5; i++){
//       for(int j = 0; j < 5; j++){
//         if(i == j) System.out.print("#");
//         else System.out.print("+");
//       }
//       System.out.println();
//     }
//   }
// }

/** 2068. 최대수 구하기
  *
  *
  *
  *
  */

// import java.lang.Math;

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();

//     int TC = Integer.parseInt(br.readLine());

//     for(int tc = 1; tc <= TC; tc++){
//       sb.append("#").append(TC).append(" ");

//       char[] input = br.readLine().toCharArray();
//       int[] arr = new int[input.length];
//       int max = 0;
//       for(int i = 0; i < input.length; i++){
//         arr[i] = input[i] - '0';
//         max = arr[i];
//         if(i > 0 && arr[i] > max){
//           max = arr[i];
//         }
//       }
//       sb.append(max).append("\n");
//     }
//     System.out.println(sb.toString());
//   }
// } // review 필요

/** 2068. 최대수 구하기
  *
  *
  *
  */

// import java.util.*;
// import java.io.*;

// public class Main{
//   public static void main(String[] args){
//     Scanner sc = new Scanner(System.in);
//     StringBuilder sb = new StringBuilder();

//     int TC = sc.nextInt();
//     int[] arr = new int[10];

//     for(int tc = 0 ; tc < TC ; tc++){
//       sb.append("#").append(tc+1).append(" ");

//       int max = -999;

//       for(int i = 0 ; i < 10 ; i++){
//         arr[i] = sc.nextInt();
//         if(arr[i] >= max) max = arr[i];
//       }
//       sb.append(max).append("\n");
//     }
//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

// import java.util.*;
// import java.io.*;

// public class Main{
//   public static void main(String[] args){

//     Scanner sc = new Scanner(System.in);
//     StringBuilder sb = new StringBuilder();

//     int TC = sc.nextInt();
//     int[] arr = new int[10];

//     for(int tc = 0 ; tc < TC ; tc++){
//       sb.append("#").append(tc+1).append(" ");
//       int max = -999;

//       for(int i = 0 ; i < 10 ; i++){
//         arr[i] = sc.nextInt();
//         if(arr[i] >= max) max = arr[i];
//       }

//       sb.append(max).append("\n");
//     }

//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

/**1933. 간단한 N 의 약수
  *
  *
  *
  */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) {
//     Scanner sc = new Scanner(System.in);
//     StringBuilder sb = new StringBuilder();
//     int N = sc.nextInt();

//     for (int n = 1; n <= N; n++) {
//       if (N % n == 0)
//         sb.append(n).append(" ");
//     }

//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

/**2029. 몫과 나머지 출력하기
  *
  *
  *
  *
  */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) {
//     StringBuilder sb = new StringBuilder();
//     Scanner sc = new Scanner(System.in);

//     int TC = sc.nextInt();

//     for (int tc = 0; tc < TC; tc++) {
//       sb.append("#").append(tc + 1).append(" ");
//       int a = sc.nextInt();
//       int b = sc.nextInt();
//       sb.append(a / b).append(" ").append(a % b).append("\n");
//     }
//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

/**2070. 큰 놈, 작은 놈, 같은 놈
  *
  *
  *
  *
  */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) {
//     StringBuilder sb = new StringBuilder();
//     Scanner sc = new Scanner(System.in);

//     int TC = sc.nextInt();
//     for (int tc = 0; tc < TC; tc++) {
//       sb.append("#").append(tc + 1).append(" ");
//       int a = sc.nextInt();
//       int b = sc.nextInt();

//       if (a - b == 0)
//         sb.append("=\n");
//       else if (a - b > 0)
//         sb.append(">\n");
//       else if (a - b < 0)
//         sb.append("<\n");
//     }

//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

/**2050. 알파벳을 숫자로 변환
  *
  *
  *
  *
  */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();

//     String str = br.readLine();
//     // char[] arr = str.toCharArray();
//     // for (int i = 0; i < arr.length; i++) {
//     // int num = (int)arr[i] - 'A' + 1;
//     for (int i = 0; i < str.length(); i++) {
//       int num = (int) str.charAt(i) - 64;
//       sb.append(num + " ");
//     }
//     System.out.println(sb.toString());
//   }
// }

/**
 * 2019. 더블더블
 *
 *
 *
 *
 */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();
//     String str = br.readLine();
//     int n = Integer.parseInt(str);

//     int m = 1;
//     for (int i = 0; i < n; i++) {
//       if (i > 0)
//         m = m * 2;
//       sb.append(m + " ");
//     }
//     System.out.println(sb.toString());
//   }
// }

/**
 * 2063. 중간값 찾기
 *
 *
 *
 *
 */

// import java.util.*;
// import java.io.*;

// public class Main{
//   public static void main(String[] args){
//     // BufferedReader br = new BufferedReader(new InputStringBuilder(System.in));
//     // StringBuilder sb = new StringBuilder();
//     Scanner sc = new Scanner(System.in);

//     // String strN = br.readLine();
//     // int N = Integer.parseInt(strN);
//     int N = sc.nextInt();
//     int[] nums = new int[N];

//     for(int i = 0 ; i < N ; i++){
//       nums[i] = sc.nextInt();
//     }
//     Arrays.sort(nums);
//     System.out.println(nums[N/2]);
//     sc.close();
//   }
// }

/**
 * 1545. 거꾸로 출력해 보아요
 *
 *
 *
 *
 */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) throws Exception {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     StringBuilder sb = new StringBuilder();

//     int N = Integer.parseInt(br.readLine());

//     for (int i = N; i >= 0; i--) {
//       sb.append(i + " ");
//     }
//     System.out.println(sb.toString());
//   }
// }

/**
 * 2072. 홀수만 더하기
 *
 *
 *
 *
 */

// import java.util.*;
// import java.io.*;

// public class Main{
//   public static void main(String[] args){
//     // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//     Scanner sc = new Scanner(System.in);
//     StringBuilder sb = new StringBuilder();

//     // int TC = Integer.parseInt(br.readLine());
//     int TC = sc.nextInt();
//     for(int tc = 1 ; tc <= TC ; tc++){
//       sb.append("#" + tc + " ");
//       int[] arr = new int[10];
//       int SUM = 0;
//       for(int i = 0 ; i<arr.length ; i++){
//         arr[i] = sc.nextInt();
//         if(arr[i] % 2 != 0){
//           SUM = SUM + arr[i];
//         }
//       }
//       sb.append(SUM + "\n");
//     }
//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

/**
 * 2071. 평균값 구하기
 *
 *
 *
 *
 */

// import java.util.*;
// import java.io.*;

// public class Main {
//   public static void main(String[] args) {
//     Scanner sc = new Scanner(System.in);
//     StringBuilder sb = new StringBuilder();

//     int TC = sc.nextInt();
//     for (int tc = 1; tc <= TC; tc++) {
//       sb.append("#" + tc + " ");
//       int sum = 0;
//       for (int i = 0; i < 10; i++) {
//         int n = sc.nextInt();
//         sum = sum + n;
//       }
//       // sb.append(Math.round(sum / (double)10) + "\n");
//       sb.append(Math.round(sum / 10.0) + "\n");
//     }
//     System.out.println(sb.toString());
//     sc.close();
//   }
// }

/**
 * 2056. 연월일 달력
 *
 *
 *
 *
 */

import java.util.*;
import java.io.*;

public class Main {

  public static int[] limit_date = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

  public static String getYear(int year) {
    return String.format("%04d", year);
  }

  public static String getMonth(int month) {
    return String.format("%02d", month);
  }

  public static String getDate(int date) {
    return String.format("%02d", date);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();

    int TC = sc.nextInt();
    for (int tc = 1; tc <= TC; tc++) {
      sb.append("#" + tc + " ");

      // int[] arr = new int[8];
      // System.out.println("arr1 : " + Arrays.toString(arr));
      // for (int i = 0; i < 8; i++) {
      // arr[i] = sc.nextInt();
      // }
      // System.out.println("arr2 : " + Arrays.toString(arr));

      // int year = arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3];
      // int month = arr[4] * 10 + arr[5];
      // int date = arr[6] * 10 + arr[7];

      String str = sc.next();
      int year = Integer.parseInt(str.substring(0, 4));
      int month = Integer.parseInt(str.substring(4, 6));
      int date = Integer.parseInt(str.substring(6, 8));

      // System.out.println("year : " + year);
      // System.out.println("month : " + month);
      // System.out.println("date : " + date);

      // if (month > 12 || month < 1) {
      // sb.append(-1);
      // }
      // if (date > limit_date[month] || date < 1) {
      // sb.append(-1);
      // }
      // sb.append(year).append("/").append(month).append("/").append(date).append("\n");

      if (month < 13 && month > 0 && date <= limit_date[month]) {
        sb.append(getYear(year))
            .append("/").append(getMonth(month))
            .append("/").append(getDate(date))
            .append("\n");
      } else
        sb.append(-1).append("\n");

    }
    System.out.println(sb.toString());
    sc.close();
  }
}

'ALGORITHM > SWEA' 카테고리의 다른 글

[SWEA D3] 13218. 조별과제  (0) 2023.03.29
[SWEA D3] 12368. 24시간  (0) 2023.03.28
[Algorithm Study] D4_3234 준환이의 양팔저울  (0) 2021.09.01
[Algorithm Study] D3_5215 햄버거 다이어트  (0) 2021.08.31
D2 review  (0) 2021.08.14