2 条题解

  • 0
    @ 2025-9-19 9:34:43

    c++题解

    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    unordered_map<int,int> cnt;
    signed main(){
    int x,q;
    char op;
    cin>>q;
    while(q--){
        cin>>op>>x;
        if(op=='I'){
           cnt[x]++;
        }
        if(op=='Q'){
            if(cnt[x]){
                cout<<"Yes"<<endl;
            }
            else cout<<"No"<<endl;
        }
    }
    }
    
    • 0
      @ 2025-5-8 22:15:03

      JAVA ac代码: 送分题,掌握set的运用

      import java.util.*;
      import java.util.StringTokenizer;
      import java.io.*;
      
      public class Main {
      
      	public static void main(String[] args) {
      		int q=in.nextInt();
      		Set<Integer> set=new HashSet<>();
      		while(q-->0){
      			String op=in.next();
      			int x=in.nextInt();
      			if(op.equals("I")){
      				set.add(x);
      			}else{
      				if(set.contains(x)) out.println("Yes");
      				else out.println("No");
      			}
      		}
      		out.close();
      	}
      	
      	
      
      	static FastReader in=new FastReader();
      	static PrintWriter out=new PrintWriter(System.out);
      	static class FastReader{
      		static BufferedReader br;
      		static StringTokenizer st;
      		FastReader(){
      			br=new BufferedReader(new InputStreamReader(System.in));
      		}
      		String next() {
      			String str="";
      			while(st==null||!st.hasMoreElements()) {
      				try {
      					str=br.readLine();
      				}catch(IOException e) {
      					throw new RuntimeException(e);
      				}
      				st=new StringTokenizer(str);
      			}
      			return st.nextToken();
      		}
      		int nextInt() {
      			return Integer.parseInt(next());
      		}
      		double nextDouble() {
      			return Double.parseDouble(next());
      		}
      		long nextLong() {
      			return Long.parseLong(next());
      		}
      	}
      	
      }
      
      
      • 1

      信息

      ID
      44
      时间
      1000ms
      内存
      256MiB
      难度
      3
      标签
      递交数
      36
      已通过
      18
      上传者