map字符串映射

输入n个字符串

查询某个字符串出现次数

#include <cstdio>
#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

#define MAXN 10001
char str[MAXN];
map<string,int> h;
int n,m;

int main () {
    cin>>n>>m;
    for (int i=1;i<=n;i++) {
        scanf("%s",str);
        h[str]++;
    }
    for (int i=1;i<=m;i++) {
        scanf("%s",str);
        if (h.find(str)==h.end()) cout<<0<<endl;
        else cout<<h[str]<<endl;
    }

    return 0;
}

 

posted @ 2018-11-10 21:17  codemaker_li  阅读(689)  评论(0编辑  收藏  举报