Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 30 |
Tags
- 파이썬
- Matrix
- Stack
- simulation
- Binary Search
- geometry
- hash table
- Data Structure
- Class
- SQL
- array
- 코딩테스트
- bit manipulation
- java
- greedy
- implement
- database
- 자바
- sorting
- 구현
- Number Theory
- Binary Tree
- Method
- dynamic programming
- Counting
- Math
- string
- Tree
- 코테
- two pointers
Archives
- Today
- Total
코린이의 소소한 공부노트
[백준 온라인 저지] 7785. 회사에 있는 사람 본문
1. 입력
- 첫째 줄에 로그에 기록된 출입 기록의 수 n이 주어진다. (2 ≤ n ≤ 10^6)
- 다음 n개의 줄에는 출입 기록이 순서대로 주어지며, 각 사람의 이름이 주어지고 "enter"나 "leave"가 주어진다. "enter"인 경우는 출근, "leave"인 경우는 퇴근이다.
- 회사에는 동명이인이 없으며, 대소문자가 다른 경우에는 다른 이름이다.
- 사람들의 이름은 알파벳 대소문자로 구성된 5글자 이하의 문자열이다.
2. 출력
- 현재 회사에 있는 사람의 이름을 사전 순의 역순으로 한 줄에 한 명씩 출력한다.
3. 코드
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.valueOf(br.readLine());
HashSet<String> set = new HashSet<>();
for(int i=0 ; i<n ; i++){
String[] input = br.readLine().split(" ");
if(set.contains(input[0])) set.remove(input[0]);
else set.add(input[0]);
}
String[] list = set.toArray(new String[0]);
Arrays.sort(list);
for(int i=list.length-1; i>=0; i--)
bw.write(list[i]+"\n");
bw.flush();
bw.close();
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 10816. 숫자 카드 2 (0) | 2023.04.18 |
---|---|
[백준 온라인 저지] 1620. 나는야 포켓몬 마스터 이다솜 (0) | 2023.04.18 |
[백준 온라인 저지] 25206. 너의 평점은 (0) | 2023.04.17 |
[백준 온라인 저지] 2941. 크로아티아 알파벳 (0) | 2023.04.17 |
[LeetCode/Easy] 1748. Sum of Unique Elements (0) | 2023.04.17 |