티스토리 뷰
Hash (해시)
Input |
Output |
첫 줄에 명령어의 개수 N이 주어집니다. (1 ≤ V ≤ 100,000) 두번째 줄부터 N개의 줄에 걸쳐 아래와 같은 형태로 명령어가 주어집니다. 1 s: 입력받은 문자열 s를 set에 추가합니다. 이미 set에 존재한다면 추가하지 않습니다. 2 s: 입력받은 문자열 s를 set에서 제거합니다. 존재하지 않는다면 아무 동작도 하지 않습니다. 3 s: 입력받은 문자열 s가 set에 있다면 1을, 없다면 0을 출력합니다. |
각 명령어에 알맞은 결과를 한줄씩 출력합니다. |
import java.util.*;
public class Test {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashSet<String> hash = new HashSet<String>();
for (int i = 0; i < n; i++) {
int command = sc.nextInt();
String key = sc.next();
if (command == 1) {
hash.add(key);
}
else if (command == 2) {
hash.remove(key);
}
else {
if (hash.contains(key)) {
System.out.println("1");
}
else {
System.out.println("0");
}
}
}
}
}
Data Structure
'Data Structure' 카테고리의 다른 글
자료구조) Tree - Binary Search Tree, Segment Tree, Binary Indexed Tree (0) | 2019.09.12 |
---|---|
자료구조) Tree - Heap, Priority Queue (힙, 우선순위 큐) (0) | 2019.09.12 |
자료구조) Tree, Binary Tree (트리, 이진트리) (0) | 2019.09.12 |
자료구조) Stack, Queue (스택, 큐) (0) | 2019.09.12 |
자료구조) List (리스트) (0) | 2019.09.12 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- bfs
- FRAGMENT
- 웹해킹
- C
- brute-force
- 우아한 테크코스
- graph
- queue
- dfs
- Java
- javascript
- OneToMany
- 프로그래머스
- 리버싱
- Stack
- JPA
- socket
- mysql
- reversing
- Android
- 개발자
- Vo
- webhacking.kr
- 회고
- git
- Data Structure
- Android Studio
- sort
- Algorithm
- 해외여행
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함