AcWing 835. Trie字符串统计
原题链接
简单
作者:
ggbond666
,
2024-09-10 15:39:50
,
所有人可见
,
阅读 1
import java.util.HashMap;
import java.util.Scanner;
public class Main {
HashMap<String, Integer> hashMap = new HashMap<>();
public static void main(String[] args) {
Main main = new Main();
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
for (int i = 0; i < N; i++) {
String op = scanner.next();
String s=scanner.next();
if (op.equals("I") ) {
main.insert(s);
} else {
System.out.println(main.query(s));
}
}
}
int query(String s) {
if(hashMap.get(s)!=null)
return hashMap.get(s);
return 0;
}
void insert(String s) {
if(hashMap.get(s)==null){
hashMap.put(s,1);
}else{
hashMap.put(s,hashMap.get(s)+1);
}
}
}