Page 7 of 7

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

Posted: Wed Dec 18, 2013 12:28 am
by brianfry713
The input file may be arbitrarily long. I used this to parse the input:
while(scanf("%d", &i) == 1) {

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

Posted: Wed Dec 18, 2013 10:42 am
by Angry Bird
Got AC. Thanks.

Re: 484-WA..PLZ help me

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

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;
}


Re: 484-WA..PLZ help me

Posted: Wed Apr 16, 2014 11:34 pm
by lbv
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.

Re: 484-again WA WA

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

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 ;
}

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

Posted: Thu Apr 17, 2014 8:14 pm
by brianfry713
Maybe the input is on more than one line.

RE 484

Posted: Thu Jun 12, 2014 6:49 am
by sajal2k8
#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?

Re: RE 484

Posted: Thu Jun 12, 2014 7:40 pm
by brianfry713
Always print a newline char at the end of the last line.

Re: RE 484

Posted: Fri Jun 20, 2014 5:47 am
by sajal2k8
Still not accepted. Any suggestion?

484 Getting wrong answer or Runtime error please help

Posted: Fri Jun 20, 2014 10:48 am
by sajal2k8
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.

Re: RE 484

Posted: Mon Jun 23, 2014 8:56 pm
by brianfry713
Post your updated code

Re: 484 Getting wrong answer or Runtime error please help

Posted: Mon Jun 23, 2014 11:30 pm
by brianfry713
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

Re: 484 Getting wrong answer or Runtime error please help

Posted: Mon Jul 07, 2014 10:12 pm
by mgavin2
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

Re: 484 Getting wrong answer or Runtime error please help

Posted: Tue Jul 08, 2014 8:01 pm
by brianfry713
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.