-
[Softeer] 스마트 물류 (lv.3)ALGORITHM/SWEXPERT|SOFTEER 2021. 11. 2. 22:44
https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=414
2021
123456789101112131415161718192021222324252627282930313233343536import java.util.*;import java.io.*;public class Main {public static int N, K;public static void main(String[] args) throws IOException {BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer(bf.readLine());N = Integer.parseInt(st.nextToken());K = Integer.parseInt(st.nextToken());st = new StringTokenizer(bf.readLine());String str = st.nextToken();char[] arr = new char[N];for(int i = 0; i < str.length(); i++) {arr[i] = str.charAt(i);}int answer = 0;for(int i = 0; i < arr.length; i++) {if(arr[i] == 'P') {for(int j = i-K; j <= i+K; j++) {if(j < 0 || j >= N) continue;if(arr[j] == 'H') {arr[j] = 'X';answer++;break;}}}}System.out.println(answer);}}cs 'ALGORITHM > SWEXPERT|SOFTEER' 카테고리의 다른 글
[Softeer] 비밀메뉴 (lv.2) (0) 2022.01.16 [Softeer] 택배 마스터 광우 (lv.3) (0) 2021.11.02 [Softeer] 동계 테스트 시점 예측 (lv.3) (0) 2021.11.02 [Softeer] GBC (lv.2) (0) 2021.11.02 [Softeer] 장애물 인식 프로그램 (lv.2) (0) 2021.11.02