390 - Letter Sequence Analysis

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am
Location: Bangladesh

390 - Letter Sequence Analysis

Post by Noim »

in the problem description there is a line:
Print a blank line between two analises.
but i got ACwithPE for printing the blank line between two analiese but got AC for printing blank line after each analises.

and also the Sample output for the line:
When the first three paragraphs of this problem description are used as input, the output should appear as shown here:


Analysis for Letter Sequences of Length 1
-----------------------------------------
Frequency = 201, Sequence(s) = (E)
Frequency = 112, Sequence(s) = (T)
Frequency = 96, Sequence(s) = (S)
Frequency = 90, Sequence(s) = (R)
Frequency = 84, Sequence(s) = (N)
............................
........................
here the frequency of E is not 201 but 206 and all the other datas are also wrong.

i think the problem description should be checkcked.......
__nOi.m....

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

http://online-judge.uva.es/board/viewto ... ed86c04ea2

The line was added and the output was not modified.

tsengct
New poster
Posts: 5
Joined: Mon Aug 27, 2007 7:11 am

Post by tsengct »

What is the output for the input
"A"
is it
Analysis for Letter Sequences of Length 1
-----------------------------------------
Frequency = 1, Sequence(s) = (A)

Analysis for Letter Sequences of Length 2
-----------------------------------------

Analysis for Letter Sequences of Length 3
-----------------------------------------

Analysis for Letter Sequences of Length 4
-----------------------------------------

Analysis for Letter Sequences of Length 5
-----------------------------------------

or
Analysis for Letter Sequences of Length 1
-----------------------------------------
Frequency = 1, Sequence(s) = (A)

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

I think this case is not correct. However, my code returns the first ouput.
Ami ekhono shopno dekhi...
HomePage

Fluffymoo
New poster
Posts: 7
Joined: Wed Oct 15, 2008 5:05 pm

Re: 390 -> wrong sample output and wrong PE judgement

Post by Fluffymoo »

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? :/

Post Reply

Return to “Volume 3 (300-399)”