484 - The Department of Redundancy Department

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

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 484-The Department of Redundancy Department Getting WA..

Post by brianfry713 » Wed Dec 18, 2013 12:28 am

The input file may be arbitrarily long. I used this to parse the input:
while(scanf("%d", &i) == 1) {
Check input and AC output for thousands of problems on uDebug!

Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

Re: 484-The Department of Redundancy Department Getting WA..

Post by Angry Bird » Wed Dec 18, 2013 10:42 am

Got AC. Thanks.

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

Re: 484-WA..PLZ help me

Post by cse dipto » Wed Apr 16, 2014 9:07 pm

Code: Select all

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <sstream>
#include <utility>

using namespace std;

vector<string> str_index ;
vector<string> str_index2 ;
map<string , int> str_counter ;
map<string , int> str_chk ;

int main()
{
    long int i,j,k,t_case,len,len2 ;
    string str,tmp ;
    while(getline(cin,str))
    {
        str_index.clear() ;
        str_counter.clear() ;
        str_chk.clear() ;
        str_index2.clear() ;
        stringstream ss(str) ;
        while(ss >> tmp)
        {
            str_index.push_back(tmp) ;
            if(str_chk[tmp] == 0)
            {
                str_index2.push_back(tmp) ;
                str_chk[tmp] = 1 ;
            }
        }
        len2 = str_index2.size() ;
        len = str_index.size() ;
        for(i = 0 ; i < len2 ; i++)
        {
            tmp = str_index2[i] ;
            for(j = 0 ; j < len ; j++)
            {
                if(str_index2[i] == str_index[j])
                {
                    str_counter[tmp]++ ;
                }
            }
        }
        for(i = 0 ; i < len2 ; i++)
        {
            tmp = str_index2[i] ;
            cout << str_index2[i] << " " << str_counter[tmp] << endl ;
        }
    }
    return 0;
}


lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 484-WA..PLZ help me

Post by lbv » Wed Apr 16, 2014 11:34 pm

cse dipto wrote:(code omitted)
It's never a good idea to make assumptions about things that are not explicitly stated in the problem statement.

In this problem, for example, it is not the case that the input contains more than one test case, and that the numbers of each test case are given on a single line. I can see how it can be tempting to assume that, by just looking at the sample I/O, but that's not what the "Input" section specifies.

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

Re: 484-again WA WA

Post by cse dipto » Thu Apr 17, 2014 3:28 pm

Code: Select all

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <sstream>
#include <utility>

using namespace std;

vector<string> str_index ;
vector<string> str_index2 ;
map<string , int> str_counter ;
map<string , int> str_chk ;

int main()
{
    long int i,j,k,t_case,len,len2 ;
    string str,tmp ;
    getline(cin , str) ;
    stringstream ss(str) ;
    while(ss >> tmp)
    {
        str_index.push_back(tmp) ;
        if(str_chk[tmp] == 0)
        {
            str_index2.push_back(tmp) ;
            str_chk[tmp] = 1 ;
        }
    }
    len2 = str_index2.size() ;
    len = str_index.size() ;
    for(i = 0 ; i < len2 ; i++)
    {
        tmp = str_index2[i] ;
        for(j = 0 ; j < len ; j++)
        {
            if(str_index2[i] == str_index[j])
            {
                str_counter[tmp]++ ;
            }
        }
    }
    for(i = 0 ; i < len2 ; i++)
    {
        tmp = str_index2[i] ;
        cout << str_index2[i] << " " << str_counter[tmp] << endl ;
    }
    return 0 ;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 484-The Department of Redundancy Department Getting WA..

Post by brianfry713 » Thu Apr 17, 2014 8:14 pm

Maybe the input is on more than one line.
Check input and AC output for thousands of problems on uDebug!

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

RE 484

Post by sajal2k8 » Thu Jun 12, 2014 6:49 am

#include <iostream>

using namespace std;

int main()
{
long long int a,n[10000],m[10000],e=0,c=0;
for( int i=0;;i++)
{
cin>>a;
if(m[a]==0)
{
n[c]=a;
e++;
c++;
}
m[a]=m[a]+1;
if(cin.get()=='\n')
break;
}
for(int i=0;i<e;i++)
{
cout<<n<<" "<<m[n];
if(i!=e-1)
cout<<endl;
}
return 0;
}


What is the problem here?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: RE 484

Post by brianfry713 » Thu Jun 12, 2014 7:40 pm

Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

Re: RE 484

Post by sajal2k8 » Fri Jun 20, 2014 5:47 am

Still not accepted. Any suggestion?

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

484 Getting wrong answer or Runtime error please help

Post by sajal2k8 » Fri Jun 20, 2014 10:48 am

Here is my code:
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;

int main()
{
int a,b=0,c=0,in[10000],out[10000];
string str;
string buf;

vector<string> tokens;
while(getline(cin,str))
{
stringstream ss(str);
while (ss >> buf)
{
tokens.push_back(buf);
a=atoi(buf.c_str());
if(b==0)
{
in=a;
out[a]++;
b++;
}
for(int i=0;i<c;i++)
{
if(a==in)
{
out[a]++;
break;
}
else if(i==c-1)
{
in=a;
b++;
c++;
}
}
if(c==0)
c++;
}
for(int i=0;i<b;i++)
{
cout<<in<<" "<<out[in]<<endl;
if(in<0)
out[in]=0;
}
std::fill_n(out, 10000, 0);
b=0,c=0;
}
return 0;
}

I have tried all possible input no error. But getting runtime error. Please help me with this one. Thanks in advance.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: RE 484

Post by brianfry713 » Mon Jun 23, 2014 8:56 pm

Post your updated code
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 484 Getting wrong answer or Runtime error please help

Post by brianfry713 » Mon Jun 23, 2014 11:30 pm

Input:

Code: Select all

3 1 2 2 1 3 5 3 3 2
3 1 2 2 1 3 5 3 3 2
AC output:

Code: Select all

3 8
1 4
2 6
5 2
Check input and AC output for thousands of problems on uDebug!

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

Re: 484 Getting wrong answer or Runtime error please help

Post by mgavin2 » Mon Jul 07, 2014 10:12 pm

This problem is awkward. At first it seems like the sample output is wrong.
3 1 2 2 1 3 5 3 3 2 should become 3 1 2 1 3 5 3 2... which means 3 3, 1 2, 2 2, 5 1... not 2 3 in the sample output

and even though brianfry's AC output conforms to this (brianfry is amazing):
brianfry713 wrote:Input:

Code: Select all

3 1 2 2 1 3 5 3 3 2
3 1 2 2 1 3 5 3 3 2
AC output:

Code: Select all

3 8
1 4
2 6
5 2
My AC output on the same sample he gave was:

Code: Select all

3 6
1 4
2 4
5 2
all that matters is AC

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 484 Getting wrong answer or Runtime error please help

Post by brianfry713 » Tue Jul 08, 2014 8:01 pm

Thanks, but I think your logic is wrong. The problem statement says nothing about removing consecutive duplicates. Just count the number of times each number appears in the input.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 4 (400-499)”