[SWEA] 삼성시의 버스 노선

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

버스 정류장이 1번부터 5000번까지있다는 것만 의식해서 count를 세준 뒤, count를 출력한다.

JAVA Code

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
import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int T = s.nextInt();
		for(int tc=1; tc<=T; tc++) {
			int N = s.nextInt();
			int[] counts = new int[5001];
			for(int i=0; i<N; i++) {
	            int A = s.nextInt();
	            int B = s.nextInt();
	            for(int j = A; j <= B; j++) {
	                counts[j]++;
	            }
		}
        System.out.print("#"+tc);
        int P = s.nextInt();
        for(int i = 0 ; i < P; i++) {
            int C = s.nextInt();
            System.out.print(" "+counts[C]);
        }
        System.out.println();
		}
	}
}