This is so simple problem...yet i keep getting WA no matter what i do, while in my tests, there are no mistakes

The frequencies and words belonging to them are correct so i guess there is either a mistake in my formatting or in the way i read data...
My output has this format.
Analysis for Letter Sequences of Length 1
-----------------------------------------
Frequency = a, Sequence(s) = (word,.....,word)
Frequency = b, Sequence(s) = (word,.....,word)
Frequency = c, Sequence(s) = (word,.....,word)
{blank line}
Analysis for Letter Sequences of Length 2
-----------------------------------------
Frequency = d, Sequence(s) = (word,.....,word)
Frequency = e, Sequence(s) = (word,.....,word)
{blank line}
Analysis for Letter Sequences of Length 3
-----------------------------------------
{blank line}
Analysis for Letter Sequences of Length 4
-----------------------------------------
{blank line}
Analysis for Letter Sequences of Length 5
-----------------------------------------
Frequency = f, Sequence(s) = (word,.....,word)
and my whole code follows
Code: Select all
#include <iostream>
#include <string>
#include <sstream>
#include <map>
using namespace std;
map<string,int>freq_1,freq_2,freq_3,freq_4,freq_5;
int MIN(int a, int b)
{
if (a<b) return a;
return b;
}
bool isCorrect(char i)
{
if(i>='A'&&i<='Z')
return true;
return false;
}
struct comparator
{
bool operator()(const int i1, const int i2) const
{
return i1>i2;
}
};
void computeResults(int i)
{
if(i>1)cout<<endl<<endl;
cout<<"Analysis for Letter Sequences of Length "<<i<<endl;
cout<<"-----------------------------------------";
map<string,int> *freq;
if(i==1)
freq=&freq_1;
else if(i==2)
freq=&freq_2;
else if(i==3)
freq=&freq_3;
else if(i==4)
freq=&freq_4;
else if(i==5)
freq=&freq_5;
int l=freq->size();
map<int,string,comparator>freq_R;
map<string,int>::iterator horse=freq->begin();
while(--l>=0)
{
if(freq_R[(*horse).second]=="")
freq_R[(*horse).second]=(*horse).first;
else
freq_R[(*horse).second]=freq_R[(*horse).second]+","+(*horse).first;
horse++;
}
map<int,string>::iterator horse_r=freq_R.begin();
l=freq_R.size();
int counter=5;
if(l>0){
while(counter--&&l--)
{
cout<<endl<<"Frequency = "<<(*horse_r).first<<", Sequence(s) = ("<<(*horse_r).second<<")";
++horse_r;
}
}
}
void outputResults()
{
int l=0;
while(l++<5)
{
computeResults(l);
}
}
void readData()
{
char read[5];
int c=0;
while((read[0]=toupper(getchar()))!=EOF)
{
string i;
if(isCorrect(read[0]))
{
i.insert(0,1,read[0]);
freq_1[i]++;
i.clear();
if(c>0)
{
i.insert(0,1,read[1]);
i.insert(1,1,read[0]);
freq_2[i]++;
i.clear();
}
if(c>1)
{
i.insert(0,1,read[2]);
i.insert(1,1,read[1]);
i.insert(2,1,read[0]);
freq_3[i]++;
i.clear();
}
if(c>2)
{
i.insert(0,1,read[3]);
i.insert(1,1,read[2]);
i.insert(2,1,read[1]);
i.insert(3,1,read[0]);
freq_4[i]++;
i.clear();
}
if(c>3)
{
i.insert(0,1,read[4]);
i.insert(1,1,read[3]);
i.insert(2,1,read[2]);
i.insert(3,1,read[1]);
i.insert(4,1,read[0]);
freq_5[i]++;
i.clear();
}
read[4]=read[3];
read[3]=read[2];
read[2]=read[1];
read[1]=read[0];
c=MIN(5,(c+1));
}
else
c=0;
}
}
int main()
{
readData();
outputResults();
return 0;
}
where did i do mistake? :/