ALGORITHM
[JAVA] 백준 10546번- 배부른 마라토너
연듀
2022. 7. 6. 11:49
https://www.acmicpc.net/problem/10546
10546번: 배부른 마라토너
마라토너라면 국적과 나이를 불문하고 누구나 참가하고 싶어하는 백준 마라톤 대회가 열린다. 42.195km를 달리는 이 마라톤은 모두가 참가하고 싶어했던 만큼 매년 모두가 완주해왔다. 단, 한 명
www.acmicpc.net
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
HashMap<String, Integer> map = new HashMap<>();
for(int i=0; i<n; i++){
String str=sc.next();
map.put(str, map.getOrDefault(str, 0)+1);
}
for(int i=0; i<n-1; i++){
String str = sc.next();
if(map.containsKey(str)) map.put(str, map.get(str)-1);
if(map.get(str)==0) map.remove(str);
}
for(String key : map.keySet()){
System.out.println(key);
}
}
}
이름과 사람수의 해시맵을 만들고 완주한 사람의 사람수를 하나씩 빼고 남는 사람 한명을 출력하면 된다.
반응형