슈콩

[SWEA] 전봇대 본문

Algorithms/SWEA

[SWEA] 전봇대

shukong 2025. 11. 12. 20:38

 

 

[코드]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXO8QBw6Qu4DFAXS

 

SW Expert Academy

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

swexpertacademy.com

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int n = Integer.parseInt(br.readLine());
			int[] a = new int[n];
			int[] b = new int[n];
			for(int i=0;i<n;i++) {
				st = new StringTokenizer(br.readLine());
				a[i] = Integer.parseInt(st.nextToken());
				b[i] = Integer.parseInt(st.nextToken());
			}
			int result = 0;
			for(int i=0;i<n-1;i++) {
				for(int j=i+1;j<n;j++) {
					if(a[i]>a[j] && b[i]<b[j] || a[i]<a[j] && b[i]>b[j]) result++;
				}
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 숫자가 같은 배수  (0) 2025.11.13
[SWEA] 상원이의 연속 합  (0) 2025.11.12
[SWEA] 1차원 정원  (0) 2025.11.12
[SWEA] 한빈이와 Spot Mart  (0) 2025.11.12
[SWEA] 퍼펙트 셔플  (0) 2025.11.12