Page 6 of 7
problem 484 WA plz help
Posted: Tue Jan 31, 2006 3:46 pm
by georgemouse
I have tried all the possible input and all are right.
But I still got WA.
Can someone tell me what is wrong??
Thanks!!!
Code: Select all
//acm484
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char *p,in[100000];
int find,c,n,t=0,times[100000][2];
for(n=0;n<100000;n++) times[n][1]=1;
gets(in);
p=strtok(in," ");
times[t++][0]=atoi(p);
while((p=strtok(NULL," "))!=0)
{
for(n=c=0;n<t;n++)
if(times[n][0]==atoi(p))
{
c=1;
find=n;
break;
}
if(c!=0) times[find][1]++;
else times[t++][0]=atoi(p);
}
for(n=0;n<t;n++) printf("%d %d\n",times[n][0],times[n][1]);
return 0;
}
Posted: Tue Jan 31, 2006 5:32 pm
by Wei-Ming Chen
I didn't think this problem should use %c, I used %d to scanf and got AC.
What made your code wrong maybe is something wrong when you changed char to int.
Or the input is look like
6 5 6
4 5
3
3
Posted: Fri Feb 03, 2006 9:48 am
by georgemouse
Thank you ,Wei-Ming Chen!!!
I've misunderstood the problem.
Now I have accepted.
Thank you very much!!!!
Best regards,
Bug
Posted: Thu Jul 27, 2006 4:44 pm
by BenderBendingRodriguez
Hello,
with the following Input & Output for
484 I found a bug in my C++ program, but I don't unterstand the problem.
_.B._ wrote:Input:
(Note that there are spaces after the numbers).
Output:
My program can handle several white spaces and empty lines between numbers well.
But it seems it can't handle a white space at the very end of the input.
Every time a white space is given at the very end of the input the last read number is read twice... Why?
My Output is:
Code: Select all
-3 1
65535 2
0 2 // <-- WRONG ANSWER
Here is my code:
Code: Select all
/* @JUDGE_ID: 48058YJ 484 C++ " " */
//@BEGIN_OF_SOURCE_CODE
#include <iostream>
#include <map>
#include <vector>
using namespace std;
bool contains(vector<int> numbers, int number)
{
for(vector<int>::iterator i = numbers.begin(); i != numbers.end(); i++)
{
if(number == *i)
{
return true;
}
}
return false;
}
int main(void)
{
int number;
map<int, unsigned int> occurrences;
vector<int> numbers;
while(!cin.eof())
{
cin >> number;
occurrences[number]++;
if(!contains(numbers, number))
{
numbers.push_back(number);
}
}
for(vector<int>::iterator i = numbers.begin(); i != numbers.end(); i++)
{
cout << *i << " " << occurrences[*i] << endl;
}
return 0;
}
//@END_OF_SOURCE_CODE
I hope some one can explain this issue, and/or give a solution.
THX in advance!
EDIT:
Code added...
Posted: Thu Jul 27, 2006 5:20 pm
by BenderBendingRodriguez
Okay nevermind I got AC now...
This is what I changed:
Code: Select all
while(cin >> number)
{
//cin >> number
...
}
Now I am happy!

problem 484 WA help
Posted: Mon Oct 13, 2008 9:02 pm
by calicratis19
can anyone give me some i/o.im having wa in it.
Re: problem 484 WA plz help
Posted: Fri Oct 17, 2008 8:24 pm
by lnr
To calicratis19.
Try this.
Input:
Output:
Code: Select all
9 1
5 1
1 1
-1 1
-8 1
-6 1
0 1
34 1
-12 1
Re: problem 484 WA plz help
Posted: Fri Oct 24, 2008 8:52 am
by calicratis19
thanks
AC

uva=484- The Department of Redundancy Department
Posted: Fri Sep 14, 2012 8:48 am
by graph_dp
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <string>
#include <map>
using namespace std;
char str[1000000];
queue<string>q;string p;
map<string,int>MP;
map<string,int>::iterator it;
int main(){
MP.clear();
char *result;
gets(str);
result = strtok(str," ");
while( result != NULL ) {
p=result;
if(!MP[p]){
q.push(p);}
MP[p]++;
result = strtok(NULL," ");
}
for(it=MP.begin();it!=MP.end();++it){
cout<<q.front()<<" "<<MP[q.front()]<<endl;
q.pop();
}
return 0;
}
WHY I AM GETTING WRONG ANSWER
Re: uva=484- The Department of Redundancy Department
Posted: Fri Sep 14, 2012 10:44 pm
by brianfry713
Try reading an int at a time instead of a line and don't use strings.
484-The Department of Redundancy Department Getting WA..
Posted: Wed Jul 03, 2013 9:49 am
by sun_kuet
got acception
Re: 484-The Department of Redundancy Department Getting WA..
Posted: Wed Jul 03, 2013 11:18 pm
by brianfry713
Change line 30 to mp[m]++;
Re: 484-The Department of Redundancy Department Getting WA..
Posted: Thu Dec 05, 2013 10:19 pm
by Angry Bird
getting WA. Pls help.
Code: Select all
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define max 100000
using namespace std;
int main()
{
char str[100000];
gets(str);
//scanf("%s",&str);
vector<int>v,v1,vm;
map<int,int>m;
char *pch = strtok (str," ");
while (pch != NULL)
{
int a=atoi(pch);
m[a]++;
v.push_back(a);
pch = strtok (NULL, " ");
}
int c=0;
int c1=0;
vm.push_back(v[0]);
for(int i=1; i<v.size(); i++)
{
c=0;
for(int j=0; j<i; j++)
{
if(v[i]==v[j])
{
c=1;
}
}
if(c==1) {}
else
{
vm.push_back(v[i]);
}
}
for(int i=0; i<vm.size(); i++)
{
cout<<m.find(vm[i])->first<<" "<<m.find(vm[i])->second;
if(i<vm.size()-1)
cout<<endl;
}
return 0;
}
Re: 484-The Department of Redundancy Department Getting WA..
Posted: Thu Dec 05, 2013 11:18 pm
by brianfry713
Print a newline char at the end of the last line.
Re: 484-The Department of Redundancy Department Getting WA..
Posted: Sun Dec 15, 2013 11:21 am
by Angry Bird
boss, again WA after adding newline.