484 - The Department of Redundancy Department
Moderator: Board moderators
-
- 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..
The input file may be arbitrarily long. I used this to parse the input:
while(scanf("%d", &i) == 1) {
while(scanf("%d", &i) == 1) {
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 21
- Joined: Mon Apr 08, 2013 8:38 am
Re: 484-The Department of Redundancy Department Getting WA..
Got AC. Thanks.
Re: 484-WA..PLZ help me
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
It's never a good idea to make assumptions about things that are not explicitly stated in the problem statement.cse dipto wrote:(code omitted)
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
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 ;
}
-
- 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..
Maybe the input is on more than one line.
Check input and AC output for thousands of problems on uDebug!
RE 484
#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?
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?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: RE 484
Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
Re: RE 484
Still not accepted. Any suggestion?
484 Getting wrong answer or Runtime error please help
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.
#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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
-
- 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
Input:AC output:
Code: Select all
3 1 2 2 1 3 5 3 3 2
3 1 2 2 1 3 5 3 3 2
Code: Select all
3 8
1 4
2 6
5 2
Check input and AC output for thousands of problems on uDebug!
Re: 484 Getting wrong answer or Runtime error please help
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):
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):
My AC output on the same sample he gave was:brianfry713 wrote:Input:AC output:Code: Select all
3 1 2 2 1 3 5 3 3 2 3 1 2 2 1 3 5 3 3 2
Code: Select all
3 8 1 4 2 6 5 2
Code: Select all
3 6
1 4
2 4
5 2
all that matters is AC
-
- 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
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!