AcWing 835. Trie字符串统计(JAVA—简短版!!)
原题链接
简单
作者:
crayon不小心
,
2021-03-26 18:36:29
,
所有人可见
,
阅读 401
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String,Integer> map = new HashMap<>(32);
String[] str = reader.readLine().split(" ");
int n = Integer.parseInt(str[0]);
for (int i = 0; i < n; i++) {
String [] arr = reader.readLine().split(" ");
String q = arr[0];
String t = arr[1];
if (q.equals("I"))
{
//插入操作
if (map.containsKey(t)) map.put(t, map.get(t) + 1);
else map.put(t,1);
}
//询问操作
else
{
if (map.containsKey(t)) System.out.println(map.get(t));
else System.out.println(0);
}
}
}
}