mochuen @ 2022-01-23 17:00:19
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;
public class Main {
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static Scanner scanner = new Scanner(new BufferedInputStream(System.in));
static int n,m,op;
// static HashMap<Integer, Integer> map1=new HashMap<>();
static HashMap<Integer,Node> map = new HashMap<>();
public static void main(String[] args) throws IOException {
n=scanner.nextInt();
m=scanner.nextInt();
while(m--!=0) {
op=scanner.nextInt();
if(op==1) {
int a=scanner.nextInt(),
b=scanner.nextInt(),
c=scanner.nextInt();
map.put(a, new Node(b, c));
}else if(op==2) {
int d=scanner.nextInt(),
e=scanner.nextInt();
out.println(map.get(d).getMap().get(e));
}
}
out.flush();
}
static class Node{
HashMap<Integer, Integer> map = new HashMap<>();
public Node(int a,int b) {
// TODO Auto-generated constructor stub
map.put(a, b);
}
public HashMap<Integer, Integer> getMap() {
return map;
}
}
}
by zj_is_NB @ 2022-05-10 10:52:28
老哥你解决了吗?我和你写的差不多
by zj_is_NB @ 2022-05-10 11:34:32
我解决了,原因在于你不能每次新建一个node,要做一个判断,如果不存在再新建一个node