Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[SW Expert Academy] 4371. 항구에 들어오는 배 본문

SW_Expert

[SW Expert Academy] 4371. 항구에 들어오는 배

코드와이 2021. 2. 4. 17:51

 

문제링크

swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AWMedCxalW8DFAXd&categoryId=AWMedCxalW8DFAXd&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=JAVA&select-1=3&pageSize=10&pageIndex=9

 

SW Expert Academy

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

swexpertacademy.com

 

package D3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class 항구에_들어오는_배 {
	
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		
		int T = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();
		
		for(int tc = 1 ; tc <= T ; tc++) {
			
			sb.append("#" + tc + " ");
			
			int num = Integer.parseInt(br.readLine());
			int[] arr = new int[num];
			
			for(int n = 0 ; n < num ; n++) {
				arr[n] = Integer.parseInt(br.readLine());
			}
			
			int ans = 0;
			for(int i = 1 ; i < num ; i++) {
				if (arr[i] == 0) continue;
				int day = arr[i] - 1;
				ans += 1;
				for(int j = i + 1 ; j < num ; j++) {
					if((arr[j] - 1 ) % day == 0) {
						arr[j] = 0;
					}
				}
			}
			sb.append(ans);
			System.out.println(sb);
			sb.setLength(0);
		}
	}
}