본문 바로가기
백준/20001 - 25000

[백준] 23275번 : Knot Knowledge(JAVA)

by lms0806 2021. 10. 22.
728x90
반응형

https://www.acmicpc.net/problem/23275

 

23275번: Knot Knowledge

The first line of input consists of an integer $n$ ($2 \le n \le 50$), the number of knots Sonja needs to learn. This is followed by a line containing $n$ distinct integers $x_1, \ldots, x_n$ ($1 \le x_i \le 1\,000$), the knots that Sonja needs to learn. F

www.acmicpc.net

풀이

첫 사이즈를 입력받고, 그 사이즈만큼 수를 입력받습니다.

그 후 사이즈 - 1 만큼 수를 입력받으면서 리스트의 값을 지웁니다.

마지막 남은 리스트의 값을 출력하면 됩니다.

 

소스코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
		
		ArrayList<Integer> arr = new ArrayList<>();
		
		int n = Integer.parseInt(br.readLine());
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		for(int i = 0; i < n; i++) {
			arr.add(Integer.parseInt(st.nextToken()));
		}
		
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i < n; i++) {
			int num = Integer.parseInt(st.nextToken());
			arr.remove(arr.get(arr.indexOf(num)));
		}
		
		System.out.print(arr.get(0));
	}
}

 

728x90
반응형

댓글