
Keyword : HashMap
해결방안
과일이름과 카운트를 받되, 같은 과일이름이라면 기존의 값과 합친다. 만약에 과일이 겹치지 않으면, 새로 입력한다.
그래서 반복문을 통해서 5이면 YES 아니면 NO로 나오게
공부
HashMap에 대해 더 자세히 공부하자.
HashMap이 익숙하지 않기에 HashMap을 익숙해지자
public class Main {
public static void main(String[] args) throws IOException {
Map<String, Integer> haliGali = new HashMap<String, Integer>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String fruit = st.nextToken();
int fruit_count = Integer.parseInt(st.nextToken());
if (haliGali.containsKey(fruit)) {
haliGali.put(fruit, haliGali.get(fruit) + fruit_count);
} else {
haliGali.put(fruit, fruit_count);
}
}
String result = "NO";
for (Map.Entry<String, Integer> entry : haliGali.entrySet()) {
if(entry.getValue()==5) {
result = "YES";
}
}
System.out.println(result);
}
}