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

georgemouse
New poster
Posts: 13
Joined: Sun Aug 28, 2005 3:39 pm
Location: Taiwan

problem 484 WA plz help

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

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post 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

georgemouse
New poster
Posts: 13
Joined: Sun Aug 28, 2005 3:39 pm
Location: Taiwan

Post by georgemouse »

Thank you ,Wei-Ming Chen!!!
I've misunderstood the problem.
Now I have accepted.
Thank you very much!!!!

Best regards,

BenderBendingRodriguez
New poster
Posts: 13
Joined: Wed Sep 08, 2004 10:54 am

Bug

Post 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:

Code: Select all

 -3 
 65535 

      65535 

  0 
(Note that there are spaces after the numbers).

Output:

Code: Select all

-3 1
65535 2
0 1
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...
When you do things right, people won't be sure you've done anything at all.

BenderBendingRodriguez
New poster
Posts: 13
Joined: Wed Sep 08, 2004 10:54 am

Post by BenderBendingRodriguez »

Okay nevermind I got AC now... :D

This is what I changed:

Code: Select all

	while(cin >> number)
	{
		//cin >> number
		
		...
	}

Now I am happy! :)
When you do things right, people won't be sure you've done anything at all.

calicratis19
Learning poster
Posts: 76
Joined: Mon Jul 21, 2008 8:50 am
Location: SUST,SYLHET,BANGLADESH.
Contact:

problem 484 WA help

Post by calicratis19 »

can anyone give me some i/o.im having wa in it. :(

Code: Select all

deleted......AC
Last edited by calicratis19 on Tue Feb 10, 2009 4:10 pm, edited 1 time in total.
Heal The World

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: problem 484 WA plz help

Post by lnr »

To calicratis19.
Try this.
Input:

Code: Select all

9 5 1 -1 -8 -6 0 34 -12
Output:

Code: Select all

9 1
5 1
1 1
-1 1
-8 1
-6 1
0 1
34 1
-12 1

calicratis19
Learning poster
Posts: 76
Joined: Mon Jul 21, 2008 8:50 am
Location: SUST,SYLHET,BANGLADESH.
Contact:

Re: problem 484 WA plz help

Post by calicratis19 »

thanks :)
AC :lol:
Heal The World

graph_dp
New poster
Posts: 7
Joined: Fri Sep 14, 2012 8:33 am

uva=484- The Department of Redundancy Department

Post 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

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

Re: uva=484- The Department of Redundancy Department

Post by brianfry713 »

Try reading an int at a time instead of a line and don't use strings.
Check input and AC output for thousands of problems on uDebug!

sun_kuet
New poster
Posts: 12
Joined: Wed Mar 27, 2013 4:28 pm

484-The Department of Redundancy Department Getting WA..

Post by sun_kuet »

got acception
Last edited by sun_kuet on Thu Jul 04, 2013 4:21 pm, edited 1 time in total.

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 »

Change line 30 to mp[m]++;
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 »

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


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 »

Print a newline char at the end of the last line.
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 »

boss, again WA after adding newline.

Post Reply

Return to “Volume 4 (400-499)”