[백준, BOJ 25757] 임스와 함께하는 미니게임 (java)
Problem Solving/BOJ

[백준, BOJ 25757] 임스와 함께하는 미니게임 (java)

728x90

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

메모리: 27,244 KB , 시간: 244 ms

사용 알고리즘: 자료 구조, 해시를 사용한 집합과 맵, 문자열

728x90

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
String command = st.nextToken();
// 인원수
int limit = command.equals("Y") ? 1 : command.equals("F") ? 2 : 3;
int result = 0;
int count = 0;
// 이미 게임을 한 사람 목록
Set<String> set = new HashSet<>();
String name;
for (int i = 0; i < N; i++) {
name = br.readLine();
if(!set.contains(name)) {
set.add(name);
count++;
if(count == limit) {
result++;
count = 0;
}
}
}
System.out.println(result);
}
}
728x90