https://school.programmers.co.kr/learn/courses/30/lessons/140108
— 문제 설명
문자열 s
가 입력되었을 때 다음 규칙을 따라서 이 문자열을 여러 문자열로 분해하려고 합니다.
s
에서 분리한 문자열을 빼고 남은 부분에 대해서 이 과정을 반복합니다. 남은 부분이 없다면 종료합니다.문자열 s
가 매개변수로 주어질 때, 위 과정과 같이 문자열들로 분해하고, 분해한 문자열의 개수를 return 하는 함수 solution을 완성하세요.
— 제한 조건
s
의 길이 ≤ 10,000s
는 영어 소문자로만 이루어져 있습니다.— 입출력 예
s | result |
---|---|
"banana" | 3 |
"abracadabra" | 6 |
"aaabbaccccabba" | 3 |
입출력 예 #1
s
="banana"인 경우 ba - na - na와 같이 분해됩니다.
입출력 예 #2
s
="abracadabra"인 경우 ab - ra - ca - da - br - a와 같이 분해됩니다.
입출력 예 #3
s
="aaabbaccccabba"인 경우 aaabbacc - ccab - ba와 같이 분해됩니다.
— 문제 풀이
class Solution {
public int solution(String s) {
int xCnt = 0;
int notXCnt = 0;
int answer = 0;
char x = '0';
for(int i=0;i<s.length();i++){
if(x=='0'){
x = s.charAt(i);
xCnt++;
continue;
}
if(x==s.charAt(i)){
xCnt++;
}else {
notXCnt++;
}
if(xCnt==notXCnt){
xCnt = 0;
notXCnt = 0;
x = '0';
answer++;
}
}
if(x != '0') answer++;
return answer;
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/160586
— 문제 설명
휴대폰의 자판은 컴퓨터 키보드 자판과는 다르게 하나의 키에 여러 개의 문자가 할당될 수 있습니다. 키 하나에 여러 문자가 할당된 경우, 동일한 키를 연속해서 빠르게 누르면 할당된 순서대로 문자가 바뀝니다.
예를 들어, 1번 키에 "A", "B", "C" 순서대로 문자가 할당되어 있다면 1번 키를 한 번 누르면 "A", 두 번 누르면 "B", 세 번 누르면 "C"가 되는 식입니다.
같은 규칙을 적용해 아무렇게나 만든 휴대폰 자판이 있습니다. 이 휴대폰 자판은 키의 개수가 1개부터 최대 100개까지 있을 수 있으며, 특정 키를 눌렀을 때 입력되는 문자들도 무작위로 배열되어 있습니다. 또, 같은 문자가 자판 전체에 여러 번 할당된 경우도 있고, 키 하나에 같은 문자가 여러 번 할당된 경우도 있습니다. 심지어 아예 할당되지 않은 경우도 있습니다. 따라서 몇몇 문자열은 작성할 수 없을 수도 있습니다.
이 휴대폰 자판을 이용해 특정 문자열을 작성할 때, 키를 최소 몇 번 눌러야 그 문자열을 작성할 수 있는지 알아보고자 합니다.
1번 키부터 차례대로 할당된 문자들이 순서대로 담긴 문자열배열 keymap
과 입력하려는 문자열들이 담긴 문자열 배열 targets
가 주어질 때, 각 문자열을 작성하기 위해 키를 최소 몇 번씩 눌러야 하는지 순서대로 배열에 담아 return 하는 solution 함수를 완성해 주세요.
단, 목표 문자열을 작성할 수 없을 때는 -1을 저장합니다.
— 제한 조건
keymap
의 길이 ≤ 100keymap
의 원소의 길이 ≤ 100keymap[i]
는 i + 1번 키를 눌렀을 때 순서대로 바뀌는 문자를 의미합니다.keymap[0]
= "ABACD" 인 경우 1번 키를 한 번 누르면 A, 두 번 누르면 B, 세 번 누르면 A 가 됩니다.keymap
의 원소의 길이는 서로 다를 수 있습니다.keymap
의 원소는 알파벳 대문자로만 이루어져 있습니다.targets
의 길이 ≤ 100targets
의 원소의 길이 ≤ 100targets
의 원소는 알파벳 대문자로만 이루어져 있습니다.— 입출력 예
keymap | targets | result |
---|---|---|
["ABACD", "BCEFD"] | ["ABCD","AABB"] | [9, 4] |
["AA"] | ["B"] | [-1] |
["AGZ", "BSSS"] | ["ASA","BGZ"] | [4, 6] |
입출력 예 #1
입출력 예 #2
입출력 예 #3
— 문제 풀이
class Solution {
public int[] solution(String[] keymap, String[] targets) {
int[] answer = new int[targets.length];
for(int i=0;i<targets.length;i++){
String target = targets[i];
int cnt = 0; // 키 누른 횟수 카운트
for(int j=0;j<target.length();j++){
String t = target.charAt(j)+"";
int min = 0; // 키를 누르는 최소 횟수
for(int k=0;k<keymap.length;k++){
if(!keymap[k].contains(t))continue;
if(min == 0) min = keymap[k].indexOf(t)+1;
else min = Math.min(min, keymap[k].indexOf(t)+1);
}
if(min == 0) {
cnt = -1;
break;
}
cnt += min;
}
answer[i] = cnt;
}
return answer;
}
}
org.springframework.boot:spring-boot-starter-actuator
management:
# 모든 엔드포인트 노출 설정
endpoints:
web:
exposure:
include: '*'
# 헬스 체크 엔드포인트 상세 정보 표시 설정
endpoint:
health:
show-details: always # 이 설정은 /actuator/health 엔드포인트
server:
port: 8080
# Actuator 엔드포인트를 서버 포트와 별개로 설정 가능
management:
server:
port: 19090
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/actuator/**").authenticated()
.and()
.httpBasic();
}
}
spring:
application:
name: sample
server:
port: 8080
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
spring:
application:
name: sample
server:
port: 8080
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
# 프로메테우스 활성화
prometheus:
enabled: true
global:
scrape_interval: 15s
scrape_configs:
- job_name: "spring-boot"
metrics_path: "/actuator/prometheus"
static_configs:
- targets: ["host.docker.internal:8080"]
docker run -d --name=prometheus -p 9090:9090 -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
docker run -d --name=grafana -p 3000:3000 grafana/grafana
dependencies {
implementation 'com.github.loki4j:loki-logback-appender:1.5.1' //추가
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
@RestController
public class SampleController {
private static final Logger logger = LoggerFactory.getLogger(SampleController.class);
@GetMapping("/")
public String hello(HttpServletResponse response) throws IOException {
logger.info("Attempted access to / endpoint resulted in 403 Forbidden");
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied");
return null;
}
}
<configuration>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://localhost:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>app=my-app,host=${HOSTNAME}</pattern>
</label>
<message class="com.github.loki4j.logback.JsonLayout" />
</format>
</appender>
<root level="DEBUG">
<appender-ref ref="LOKI" />
</root>
</configuration>
https://grafana.com/docs/loki/latest/setup/install/docker/ 문서 참고
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://localhost:9093
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/analytics/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
# reporting_enabled: false
docker run --name loki -d -v ${loki-config.yml 이 저장된 폴더}:/mnt/config -p 3100:3100 grafana/loki:3.0.0 -config.file=/mnt/config/loki-config.yml