https://school.programmers.co.kr/learn/courses/30/lessons/150370
— 문제 설명
고객의 약관 동의를 얻어서 수집된 1~n
번으로 분류되는 개인정보 n
개가 있습니다. 약관 종류는 여러 가지 있으며 각 약관마다 개인정보 보관 유효기간이 정해져 있습니다. 당신은 각 개인정보가 어떤 약관으로 수집됐는지 알고 있습니다. 수집된 개인정보는 유효기간 전까지만 보관 가능하며, 유효기간이 지났다면 반드시 파기해야 합니다.
예를 들어, A라는 약관의 유효기간이 12 달이고, 2021년 1월 5일에 수집된 개인정보가 A약관으로 수집되었다면 해당 개인정보는 2022년 1월 4일까지 보관 가능하며 2022년 1월 5일부터 파기해야 할 개인정보입니다.
당신은 오늘 날짜로 파기해야 할 개인정보 번호들을 구하려 합니다.
모든 달은 28일까지 있다고 가정합니다.
다음은 오늘 날짜가 2022.05.19
일 때의 예시입니다.
약관 종류 | 유효기간 |
---|---|
A | 6 달 |
B | 12 달 |
C | 3 달 |
번호 | 개인정보 수집 일자 | 약관 종류 |
---|---|---|
1 | 2021.05.02 | A |
2 | 2021.07.01 | B |
3 | 2022.02.19 | C |
4 | 2022.02.20 | C |
따라서 파기해야 할 개인정보 번호는 [1, 3]입니다.
오늘 날짜를 의미하는 문자열 today
, 약관의 유효기간을 담은 1차원 문자열 배열 terms
와 수집된 개인정보의 정보를 담은 1차원 문자열 배열 privacies
가 매개변수로 주어집니다. 이때 파기해야 할 개인정보의 번호를 오름차순으로 1차원 정수 배열에 담아 return 하도록 solution 함수를 완성해 주세요.
— 제한 조건
today
는 "YYYY
.MM
.DD
" 형태로 오늘 날짜를 나타냅니다.terms
의 길이 ≤ 20terms
의 원소는 "약관 종류
유효기간
" 형태의 약관 종류
와 유효기간
을 공백 하나로 구분한 문자열입니다.약관 종류
는 A
~Z
중 알파벳 대문자 하나이며, terms
배열에서 약관 종류
는 중복되지 않습니다.유효기간
은 개인정보를 보관할 수 있는 달 수를 나타내는 정수이며, 1 이상 100 이하입니다.privacies
의 길이 ≤ 100privacies[i]
는 i+1
번 개인정보의 수집 일자와 약관 종류를 나타냅니다.privacies
의 원소는 "날짜
약관 종류
" 형태의 날짜
와 약관 종류
를 공백 하나로 구분한 문자열입니다.날짜
는 "YYYY
.MM
.DD
" 형태의 개인정보가 수집된 날짜를 나타내며, today
이전의 날짜만 주어집니다.privacies
의 약관 종류
는 항상 terms
에 나타난 약관 종류
만 주어집니다.today
와 privacies
에 등장하는 날짜
의 YYYY
는 연도, MM
은 월, DD
는 일을 나타내며 점(.
) 하나로 구분되어 있습니다.YYYY
≤ 2022MM
≤ 12MM
이 한 자릿수인 경우 앞에 0이 붙습니다.DD
≤ 28DD
가 한 자릿수인 경우 앞에 0이 붙습니다.— 입출력 예
today | terms | privacies | result |
---|---|---|---|
"2022.05.19" | ["A 6", "B 12", "C 3"] | ["2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"] | [1, 3] |
"2020.01.01" | ["Z 3", "D 5"] | ["2019.01.01 D", "2019.11.15 Z", "2019.08.02 D", "2019.07.01 D", "2018.12.28 Z"] | [1, 4, 5] |
입출력 예 #1
입출력 예 #2
약관 종류 | 유효기간 |
---|---|
Z | 3 달 |
D | 5 달 |
번호 | 개인정보 수집 일자 | 약관 종류 |
---|---|---|
1 | 2019.01.01 | D |
2 | 2019.11.15 | Z |
3 | 2019.08.02 | D |
4 | 2019.07.01 | D |
5 | 2018.12.28 | Z |
오늘 날짜는 2020년 1월 1일입니다.
— 문제 풀이
import java.util.*;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
int[] validate = new int[26];
for(int i=0;i<terms.length;i++){
validate[(int)(terms[i].charAt(0)-'A')] = Integer.parseInt(terms[i].split(" ")[1]);
}
String[] tmp = today.split("\\.");
int todayY = Integer.parseInt(tmp[0]);
int todayM = Integer.parseInt(tmp[1]);
int todayD = Integer.parseInt(tmp[2]);
List<Integer> list = new ArrayList<>();
for(int i=0;i<privacies.length;i++){
tmp = privacies[i].substring(0,10).split("\\.");
int privacyY = Integer.parseInt(tmp[0]);
int privacyM = Integer.parseInt(tmp[1]);
int privacyD = Integer.parseInt(tmp[2]);
int validateM = validate[(int)(privacies[i].charAt(11)-'A')];
if(privacyM + validateM <=12){
privacyM += validateM;
}else{
privacyY += (privacyM + validateM) / 12;
privacyM = (privacyM + validateM) % 12;
if(privacyM==0){
privacyY--;
privacyM = 12;
}
}
if(privacyD==1){
privacyD=28;
privacyM--;
if(privacyM==0){
privacyM=12;
privacyY--;
}
}else{
privacyD--;
}
int t = todayY * 10000 + todayM * 100 + todayD;
int p = privacyY * 10000 + privacyM * 100 + privacyD;
if(p<t) list.add(i+1);
}
int[] answer = new int[list.size()];
for(int i=0;i<list.size();i++){
answer[i] = list.get(i);
}
return answer;
}
}
9팀은 프로젝트를 아래와 같이 4개의 서버로 구성
- Eureka Server
- Gateway
- Service
- Auth
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
spring:
profiles:
default: dev
application:
name: eureka-server
server:
port: 19090
spring:
config:
activate:
on-profile: dev
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:19090/eureka/
instance:
hostname: localhost
dependencies {
// Swagger
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
spring:
profiles:
default: dev
application:
name: service
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
show_sql: true
use_sql_comments: true
highlight_sql: true
server:
port: 19092
servlet:
context-path: /api
springdoc:
swagger-ui:
path: /service/swagger-ui
api-docs:
path: /service/v3/api-docs
spring:
config:
activate:
on-profile: dev
datasource:
url: jdbc:postgresql://localhost:5432/blue
username: blue
password: 1234
driver-class-name: org.postgresql.Driver
data:
redis:
host: localhost
port: 6379
username: default
password: systempass
eureka:
client:
service-url:
defaultZone: http://localhost:19090/eureka/
@OpenAPIDefinition(
info = @Info(title = "블루팀 Service API 명세서",
description = "블루팀 Service API 명세서",
version = "v1"))
@Configuration
public class SwaggerConfig {
@Bean
public GroupedOpenApi publicAPI(){
return GroupedOpenApi.builder()
.group("com.blue.service")
.pathsToMatch("/**")
.build();
}
@Bean
public OpenAPI customOpenAPI(){
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("JWT-Token", new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(SecurityScheme.In.HEADER)
.name("Authorization")))
.addSecurityItem(new SecurityRequirement().addList("JWT-Token"));
}
}
dependencies {
// Swagger
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.2.0'
// JWT
implementation 'io.jsonwebtoken:jjwt:0.12.6'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
spring:
profiles:
default: dev
application:
name: auth
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
show_sql: true
use_sql_comments: true
highlight_sql: true
server:
port: 19093
servlet:
context-path: /api
springdoc:
swagger-ui:
path: /auth/swagger-ui
api-docs:
path: /auth/v3/api-docs
service:
jwt:
secret-key: # JWT 시크릿 키
spring:
config:
activate:
on-profile: dev
datasource:
url: jdbc:postgresql://localhost:5432/blue
username: blue
password: 1234
driver-class-name: org.postgresql.Driver
data:
redis:
host: localhost
port: 6379
username: default
password: systempass
eureka:
client:
service-url:
defaultZone: http://localhost:19090/eureka/
@OpenAPIDefinition(
info = @Info(title = "블루팀 Auth API 명세서",
description = "블루팀 Auth API 명세서",
version = "v1"))
@Configuration
public class SwaggerConfig {
@Bean
public GroupedOpenApi publicAPI(){
return GroupedOpenApi.builder()
.group("com.blue.auth")
.pathsToMatch("/**")
.build();
}
@Bean
public OpenAPI customOpenAPI(){
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("JWT-Token", new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(SecurityScheme.In.HEADER)
.name("Authorization")))
.addSecurityItem(new SecurityRequirement().addList("JWT-Token"));
}
}
dependencies {
// Swagger
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webflux-ui', version: '2.2.0'
// JWT
implementation 'io.jsonwebtoken:jjwt:0.12.6'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
server:
port: 19091
spring:
profiles:
default: dev
main:
web-application-type: reactive
application:
name: gateway
cloud:
gateway:
routes:
- id: auth
uri: lb://auth
predicates:
- Path=/api/auth/**
- id: service
uri: lb://service
predicates:
- Path=/api/**
discovery:
locator:
enabled: true
springdoc:
swagger-ui:
enabled: true
path: /swagger-ui.html
config-url: /v3/api-docs/swagger-config
urls:
- url: /api/service/v3/api-docs
name: Team Blue Service API 문서
- url: /api/auth/v3/api-docs
name: Team Blue Auth API 문서
api-docs:
enabled: true
service:
jwt:
secret-key: # JWT 시크릿 키
spring:
config:
activate:
on-profile: dev
eureka:
client:
service-url:
defaultZone: http://localhost:19090/eureka/