I assume that you are using a map to store the number of occurrences. Well, first you need to understand this, since you are using a card, the key is unique, while the stored data may not be unique. Consider a mapping x with content
x["I"]=3
x["Love"]=3
x["C"]=5
There is a unique mapping from key to value, and not vice versa, if you need this one to one mapping, I would suggest a different data structure. If you want to use the map and still search for the item using the STL search function or your own. Or you can write your search function.
search () .
map<string,int>::iterator ser;
cin>>check;
for(ser=x.begin();ser!=x.end();++ser)
{
if(ser->second==check)
{
cout<<"Word"<<ser->first<<endl;
break;
}
}
source
share