can anybody help me? i dont know where is the error.. if is in the code please let me know or if the problems is in the specifications, what is the item that i dont understand well?
thanks in advance.
there is my code.
#include <iostream>
#include <algorithm>
#include <string.h>
#include <map>
using namespace std;
int hashkey(const string s) {
unsigned long hashk=0;
for(unsigned int i=4, j=1;i<s.size();i++, j++)
hashk+=s.at(i)*j;
return ((19*hashk)%101);
}
int main(int argc, char *argv[]) {
int casos,operaciones;//casos <100 y oper<1000
cin>>casos;
string s;
while(casos--){
map<int ,string , less< int > > mstr;
cin>>operaciones;
while(operaciones--){
cin>>s;
int hkey = hashkey(s);/*guardar en un int el valor de la f()*/
if(s.at(0)=='A'){
s=s.substr(4);
//int bandera=1;
map<int ,string , less< int > >::const_iterator cIter=mstr.begin();
while(cIter != mstr.end() && (cIter->second)!=s){
cIter++;
}
if(cIter==mstr.end()){
map<int ,string , less< int > >::const_iterator cIt= mstr.find(hkey);
if(cIt==mstr.end())
mstr[hkey]=s;
else{
for(int j=1;j<20;j++){
hkey=((hkey+(j*j)+(23*j))%101);
cIt = mstr.find(hkey);
if(cIt==mstr.end()){
mstr[hkey]=s;
j=20;
}
}//fin del for que rebusca la clave hash
}//fin del else que agrega valores
}//fin del if interno
}//fin del if ADD:
else{
map<int ,string , less< int > >::const_iterator cIter1=mstr.begin();
if(cIter1==mstr.end()){
while(cIter1 != mstr.end() && (cIter1->second)!=s){
cIter1++;
}
if(cIter1!=mstr.end())
mstr.erase(hkey);
}
else
mstr.erase(hkey);
}
}//fin del while de operaciones
cout<<mstr.size()<<endl;
for( map<int ,string , less< int > >::const_iterator iter1 = mstr.begin(); iter1!=mstr.end(); iter1++)
cout<<iter1->first<<':'<<iter1->second<<endl;
mstr.clear();
}//fin del while de casos
return 0;
}