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 ]
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
map<string, set<string> > itq; // key is ip
map<string, set<string> > qti; // key is qq
string qq, ip;
int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> qq >> ip;
itq[ip].insert(qq); // ip is the key
qti[qq].insert(ip); // qq is the key
}
set<string>::iterator b; // 一个key下对应的多个
cin >> ip;
if (itq.find(ip) == itq.end()) {
cout << "no qq" << endl;
} else {
cout << ip << " ==> [ ";
for (b = itq[ip].begin(); b != itq[ip].end(); b++) {
cout << *b << " "; // 输出一个ip对应的多个qq
}
cout << "]" << endl;
}
cin >> qq;
if (qti.find(qq) == qti.end()) {
cout << "no ip" << endl;
} else {
cout << qq << " ==> [ ";
for (b = qti[qq].begin(); b != qti[qq].end(); b++) {
cout << *b << " "; // 输出一个qq对应的多个ip
}
cout << "]" << endl;
}
return 0;
}