c++11::std::unordered_map::demo

来源:互联网 发布:msde和sql 编辑:程序博客网 时间:2024/05/18 03:26
#include<string>#include<iostream>#include<unordered_map>using namespace std;struct Node{    string s;};hash<string> h;struct hashcode{    size_t operator () (const Node & r) const    {        size_t res=0;        for(int i=0;i<18;i++)            res=(res+(size_t)r.s[i]*r.s[i]*i*i*i)%3000007;        return res;    }};struct hashequal{    bool operator () (const Node & a,const Node & b) const    {        return a.s==b.s;    }};unordered_map<Node,int,hashcode,hashequal,allocator< pair<const Node, int > > > a(500007);int main(){    ios::sync_with_stdio(false);    int n,k;    cin>>n>>k;    Node s;    int t;    while(n--)    {        cin>>s.s>>t;        a[s]+=(t>=k?t:k);    }    cin>>n;    while(n--)    {        cin>>s.s;        int res=a[s];        if(res==0) cout << "No Info" << endl;        else cout << res << endl;    }    return 0;}
0 0
原创粉丝点击