https://www.codetree.ai/missions/8/problems/hashmap-basic?&utm_source=clipboard&utm_medium=text
이 문제는 제목 그대로 HashMap의 이용을 기본으로 하는 문제이다.
https://ethereal-coder.tistory.com/153
기본 개념은 여기에 있다.
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
HashMap<Integer,Integer> m = new HashMap<>();
StringTokenizer st;
StringBuilder sb = new StringBuilder();
for(int i = 0;i<n;i++){
st = new StringTokenizer(br.readLine());
String k = st.nextToken();
if(k.equals("add")){
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
m.put(a,b);
}
else if(k.equals("find")){
int a = Integer.parseInt(st.nextToken());
if(m.containsKey(a)){
sb.append(m.get(a) + "\n");
}
else sb.append("None\n");
}
else if(k.equals("remove")){
int a = Integer.parseInt(st.nextToken());
m.remove(a);
}
}
System.out.println(sb);
}
}
'알고리즘 > 코드트리 문제풀이' 카테고리의 다른 글
코드트리 [자바 java] TreeSet 기본 (0) | 2023.09.06 |
---|---|
코드트리 [자바 java] HashSet 기본 (0) | 2023.09.06 |
코드트리 [자바 java] TreeMap기본 (0) | 2023.09.06 |
코드트리 [자바 java] 가장 짧은 부분합 (0) | 2023.09.01 |
코드트리 [자바 java] 괄호 쌍 만들어주기 (0) | 2023.09.01 |