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
Code:
#include<iostream>
#include<string>
#include<set>
#include<iterator>
using namespace std;
int main()
{
int n;
cin >> n;
cin.get();
string qq[100];
string ips[100];
string reqq;
string reips;
for(int i = 0; i < n; i++)
{
cin >> qq[i] >> ips[i];
}
cin >> reips >> reqq;
string qqfin[100];
string ipsfin[100];
int countqq = 0;
int countips = 0;
for(int i = 0; i <= n; i++)
{
if (ips[i] == reips)
{
int judge = 1;
for(int j = 0; j < countqq; j++)
{
if (qqfin[j] == qq[i])
judge = 0;
}
if (judge)
{
qqfin[countqq] = qq[i];
countqq++;
}
}
if (qq[i] == reqq)
{
int judge = 1;
for(int j = 0; j < countips; j++)
{
if (ipsfin[j] == ips[i])
judge = 0;
}
if (judge)
{
ipsfin[countips] = ips[i];
countips++;
}
}
}
set<string> QQFIN(qqfin,qqfin+countqq);
set<string> IPSFIN(ipsfin,ipsfin+countips);
ostream_iterator<string, char> out (cout, " ");
if(countqq ==0)
{
cout << "no qq" << endl;
}
else
{
cout << reips << " ==> [ " ;
copy(QQFIN.begin(), QQFIN.end(), out);
cout << "]" << endl;
}
if(countips ==0)
{
cout << "no ip" << endl;
}
else
{
cout << reqq << " ==> [ " ;
copy(IPSFIN.begin(), IPSFIN.end(), out);
cout << "]" << endl;
}
return 0;
}