[STL]IP and QQ (eden)

Descrption

An ip can login several qqs, and a qq can be logined by several ips.

Your task is to find which qqs have been logined by the ip and which ips have logined the qq.

output format : qq ==> [ ip1 ip2 … ] and ip ==> [ qq1 qq2 … ]

if no such qq or ip, output “no qq” and “no ip”

First input n, then n+2 lines follow..

n lines:

qq ip

2 lines:

ip // find which qqs have been logined by the ip

qq // find which ips have logined the qq.

sample input:

5  
10258279649 192.168.1.45  
10258279649 192.168.1.45  
10258279643 192.168.1.40  
10258279640 192.168.1.45  
10258279641 192.168.1.30  
192.168.1.45  
10258279649  

sample output:

192.168.1.45 ==> [ 10258279640 10258279649 ]  
10258279649 ==> [ 192.168.1.45 ]  

Hint

map

set

From: 黄浩然

Submission

#include <iostream>
#include <map>
#include <set>
using namespace std;

int main(){
    map<string,set<string>> QQ,IP;
    int count;
    cin>>count;
    while(count--){
        string q,i;
        cin>>q>>i;
        QQ[q].insert(i);//利用map下标访问的特性,键值不存在则插入该键
        IP[i].insert(q);
    }
    string i,q;
    cin>>i>>q;
    auto iter=IP.find(i);
    if(iter==IP.end())
        cout<<"no qq\n";
    else{
        cout<<i<<" ==> [ ";
        set<string> tem=(*iter).second;
        for(auto a:tem)
            cout<<a<<" ";
        cout<<"]\n";
    }
    auto itor=QQ.find(q);
    if(itor==QQ.end())
        cout<<"no ip\n";
    else{
        cout<<q<<" ==> [ ";
        set<string> tem=(*itor).second;
        for(auto a:tem)
            cout<<a<<" ";
        cout<<"]\n";
    }
}

猜你喜欢

转载自blog.csdn.net/z_j_q_/article/details/72873525
qq