T609561 【map模板】字符串查询系统

 

 

#include<bits/stdc++.h>
using namespace std;
int n,m;  // n-集合中字符串数量,m-查询次数
map<string,int> vis;  // 使用map存储字符串出现情况

int main()
{    
    cin >> n;  // 读取字符串集合数量
    string x;  // 临时存储字符串变量
    for(int i = 1; i <= n; i++)  // 循环读取n个字符串
    {
        cin >> x;  // 读取当前字符串
        vis[x] = 1;  // 在map中标记该字符串存在
    }
    cin >> m;   // 读取查询次数
    while(m--)  // 处理每个查询
    {
        cin >> x;  // 读取查询字符串
        if(vis[x]) cout << "YES" << endl;  // 如果字符串存在
        else cout << "NO" << endl;  // 如果字符串不存在
    } 
    return 0;
}

 

posted @ 2025-05-20 17:22  CRt0729  阅读(10)  评论(0)    收藏  举报