I need to speed this code at least 2 times!
- by Dominating
include
include
include
include
using namespace std;
inline void PrintMapName(multimap pN, string s)
{
pair::iterator, multimap::iterator ii;
multimap::iterator it;
ii = pN.equal_range(s);
multimap tmp;
for(it = ii.first; it != ii.second; ++it)
{
tmp.insert(pair(it-second,1));
}
multimap::iterator i;
bool flag = false;
for(i = tmp.begin(); i != tmp.end(); i++)
{
if(flag)
{
cout<<" ";
}
cout<first;
if(flag)
{
cout<<" ";
}
flag = true;
}
cout<
int main()
{
multimap phoneNums;
multimap numPhones;
int N;
cinN;
int tests;
string tmp, tmp1,tmp2;
while(N 0)
{
cintests;
while(tests 0)
{
cintmp;
if(tmp == "add")
{
cintmp1tmp2;
phoneNums.insert(pair(tmp1,tmp2));
numPhones.insert(pair(tmp2,tmp1));
}
else
{
if(tmp == "delnum")
{
cintmp1;
multimap::iterator it;
multimap::iterator tmpr;
for(it = phoneNums.begin(); it != phoneNums.end();it++)
{
tmpr = it;
if(it-second == tmp1)
{
phoneNums.erase(it,tmpr);
}
}
numPhones.erase(tmp1);
}
else
{
if(tmp == "delname")
{
cintmp1;
phoneNums.erase(tmp1);
multimap::iterator it;
multimap::iterator tmpr;
for(it = numPhones.begin(); it != numPhones.end();it++)
{
tmpr = it;
if(it-second == tmp1)
{
numPhones.erase(it,tmpr);
}
}
}
else
{
if(tmp =="queryname")
{
cintmp1;
PrintMapName(phoneNums, tmp1);
}
else//querynum
{
cintmp1;
PrintMapName(numPhones, tmp1);
}
}
}
}
tests--;
}
N--;
}
return 0;
}