I am able to build a logic which does exactly how I want it to work but when I add more records there are some problems in flagging.
Here is the example:-
when my input is :
mymm.insert(pair<char,int>('a',50));
mymm.insert(pair<char,int>('b',100));
mymm.insert(pair<char,int>('b',150));
mymm.insert(pair<char,int>('b',200));
mymm.insert(pair<char,int>('c',250));
mymm.insert(pair<char,int>('c',300));
mymm.insert(pair<char,int>('d',300));
output is correct :-
single 50
starterminal 100
middle 150
terminal 200
starterminal 250
terminal 300
single 300
But when I change my input like this:-
mymm.insert(pair<string,string>('a',50));
mymm.insert(pair<char,int>('b',100));
mymm.insert(pair<char,int>('b',150));
mymm.insert(pair<char,int>('b',200));
mymm.insert(pair<char,int>('c',250));
mymm.insert(pair<char,int>('c',300));
mymm.insert(pair<char,int>('d',300));
mymm.insert(pair<char,int>('e',250));
mymm.insert(pair<char,int>('e',300));
The output is not correct:-
single 50
starterminal 100
middle 150
terminal 200
starterminal 250
terminal 300
single 300
terminal 250
terninal 300
Here is my code:-
// multimap::count
#include <iostream>
#include <map>
#include<vector>
using namespace std;
int main ()
{
multimap<char,int> mymm;
multimap<char,int>::iterator it;
multimap<char, int>::const_iterator m1_cIter;
char c;
mymm.insert(pair<string,string>('a',50));
mymm.insert(pair<char,int>('b',100));
mymm.insert(pair<char,int>('b',150));
mymm.insert(pair<char,int>('b',200));
mymm.insert(pair<char,int>('c',250));
mymm.insert(pair<char,int>('c',300));
mymm.insert(pair<char,int>('d',300));
mymm.insert(pair<char,int>('e',250));
mymm.insert(pair<char,int>('e',300));
int i = 0;
int k = 0;
for (c='a'; c<='z'; c++)
{
for (it=mymm.equal_range(c).first; it!=mymm.equal_range(c).second; ++it)
if((int)mymm.count(c)>2){
if(i==0){
cout << "start"<<"\t"<<(*it).second << endl;
}
else if(i>0 && i < ( mymm.count(c) - 1)){
cout << "middle"<<"\t"<<(*it).second << endl;
}
else {
cout << "terminal"<<"\t"<<(*it).second << endl;
}
i++;
}
/////////////
else if((int)mymm.count(c)==1){
cout << "single"<<"\t"<<(*it).second << endl;
}
/////////////
/////////////
else if((int)mymm.count(c)==2){
if(k==0){
cout << "start" << "\t"<< (*it).second << endl;
}
else {
cout << "terminal" << "\t" << (*it).second << endl;
}
k++;
}
////////////
}
return 0;
}
Can somebody point out my mistake ? Where am I doing mistake ?
Thanks