728x90
https://school.programmers.co.kr/learn/courses/30/lessons/150370
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;
class Solution {
public ArrayList<Integer> solution(String today, String[] terms, String[] privacies) {
ArrayList<Integer> answer = new ArrayList<Integer>();
HashMap<String, Integer> hash = new HashMap<String, Integer>();
int todayY = Integer.parseInt(today.substring(0, 4));
int todayM = Integer.parseInt(today.substring(5, 7));
int todayD = Integer.parseInt(today.substring(8));
for(String x : terms){
String termKind = x.substring(0,1);
int termM = Integer.parseInt(x.substring(2));
int num = 0, year = 0, month = 0;
if(todayM > termM){
hash.put(termKind, todayY*10000+(todayM-termM)*100+todayD);
}else if(todayM == termM){
hash.put(termKind, (todayY-1)*10000+1200+todayD);
}else{
num = todayY*12+todayM-termM;
if(num%12 == 0){
month = 12;
year = num / 12 - 1;
}else{
month = num % 12;
year = num / 12;
}
hash.put(termKind, year*10000+month*100+todayD);
}
}
for(int i = 0; i<privacies.length; i++){
String x = privacies[i];
int priDate = Integer.parseInt(x.substring(0, 4))*10000+Integer.parseInt(x.substring(5, 7))*100+Integer.parseInt(x.substring(8, 10));
String tKind = x.substring(x.length() - 1);
System.out.println(hash.get(tKind) + " " + priDate);
if(hash.get(tKind) >= priDate){
answer.add(i+1);
}
}
return answer;
}
}
'오늘의 취준 > 오늘의 코테' 카테고리의 다른 글
[JAVA] 알고리즘 문제풀이 입문 7-4, 7-5 (0) | 2023.08.17 |
---|---|
[JAVA] 알고리즘 문제풀이 입문 7-2, 7-3번 (0) | 2023.08.16 |
[JAVA] 알고리즘 문제풀이 입문 7-1번 (0) | 2023.08.15 |
[JAVA] 알고리즘 문제풀이 입문 6-9, 6-10 (0) | 2023.08.14 |
[JAVA] 알고리즘 문제풀이 입문 6-7, 6-8 (0) | 2023.08.12 |