๐ŸŒžAlgorithm/๐Ÿ”ฅBaekjoon

[Baekjoon] 17599_Bags

๋ฟŒ์•ผ._. 2025. 2. 28. 17:13
๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/17599)

< Bags >

 

๋ฌธ์ œ ํ’€์ด 

 

HashSet์„ ์‚ฌ์šฉํ•˜์—ฌ ๋…์„ฑ ํ๊ธฐ๋ฌผ์„ ์•ˆ์ „ํ•˜๊ฒŒ ์ˆ˜์ง‘ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ตœ์†Œ ์“ฐ๋ ˆ๊ธฐ๋ด‰ํˆฌ ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค.

 

my solution (Java)

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

public class _17599_ { // Bags

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		int n = Integer.parseInt(bf.readLine());

		HashSet<Integer> set = new HashSet<>();
		st = new StringTokenizer(bf.readLine());
		for (int i = 0; i < n; i++) {
			set.add(Integer.parseInt(st.nextToken()));
		}

		System.out.println(set.size());
	}
}
๋ณ€์ˆ˜)
n : ๋…์„ฑ ํ๊ธฐ๋ฌผ ์ˆ˜
set : ๋…์„ฑ ํ๊ธฐ๋ฌผ ์ข…๋ฅ˜

 

๋…์„ฑ ํ๊ธฐ๋ฌผ ์ˆ˜ n์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. n๊ฐœ๋งŒํผ ๋…์„ฑ ํ๊ธฐ๋ฌผ์˜ ์‹๋ณ„์ž๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ HashSet์— ์ €์žฅํ•œ๋‹ค. ์ตœ์ข… HashSet์˜ ํฌ๊ธฐ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.



 

'๐ŸŒžAlgorithm > ๐Ÿ”ฅBaekjoon' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Baekjoon] 12723_Minimum Scalar Product (Small)  (0) 2025.03.11
[Baekjoon] 24155_ๅพ—็‚น (Score)  (0) 2025.03.10
[Baekjoon] 5092_Air Old Zeeland  (0) 2025.02.27
[Baekjoon] 8975_PJESMA  (0) 2025.02.26
[Baekjoon] 14534_String Permutation  (0) 2025.02.25