[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";
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值