Java。案列能过,自己输入的案列也没有问题,我错哪里了,我是菜鸡
查看原帖
Java。案列能过,自己输入的案列也没有问题,我错哪里了,我是菜鸡
1047129
xieyang1234楼主2023/11/18 23:39
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException{
        Scanner sc=new Scanner(System.in);
        PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out));
        int n=sc.nextInt();
        Map<String,Integer> map=new HashMap<>();
        for (int i = 0; i < n; i++) {
           int x=sc.nextInt();
           if (x==1) {
               String str=sc.next();
               int q=sc.nextInt();
               if (map.containsKey(str)){
                    map.put(str,q);
               }
               else {
                   map.put(str,q);
                   pw.println("OK");
               }
           }else
               if (x==2){
                   String str=sc.next();
                   if (map.containsKey(str)){
                       pw.println(map.get(str));
                   }else pw.println("Not found");
               }
               else if (x==3){
                   String str=sc.next();
                   if (map.containsKey(str)){
                       map.remove(str);
                       pw.println("Deleted successfully");
                   }
                   else pw.println("Not found");
               }
               else pw.println(map.size());
        }
        pw.flush();
    }
}
2023/11/18 23:39
加载中...