Page 4 of 10

I tried it Abhishek

Posted: Mon Dec 15, 2003 1:47 pm
by aakash_mandhar
i tried that but i still get wa...
:evil: i am angry.........

anyways thx for the help..
did u get accepted..

plz try with my code itself...

Aakash

Posted: Mon Dec 15, 2003 3:18 pm
by abishek
obviously you don't subtract the cash that you have from you when the number of ppl is 0.

try again
best of luck
[cpp]

if(strcmp(a[j],name)==0) {money[j]-=cash;if(people) money[j]+=cash%people; break;}
[/cpp]

Posted: Tue Jun 01, 2004 9:13 am
by WR
Hi,

I don't think this is a multiple input problem as it has no blue tick mark.

There are just several test cases with no blank lines between them.

But of course I could be wrong which would explain the Wrong Answer my program gets. Perhaps somebody could verify the following I/O and add more cases?

input:

Code: Select all

5
dave laura owen vick amr
dave 200 3 laura owen vick
owen 500 1 dave
amr 150 2 vick owen
laura 0 2 amr vick
vick 0 0
3
liz steve dave
liz 30 1 steve
steve 55 2 liz dave
dave 0 2 steve liz
1
mary
mary 20 0
2
123456789012 123456789012
123456789012 0 0
123456789012 0 0
2
noim nahid
noim 10 0
nahid 9 0
2
one two
one 100 0
two 10 1 one
output:

Code: Select all

dave 302
laura 66
owen -359
vick 141
amr -150

liz -3
steve -24
dave 27

mary 0

123456789012 0
123456789012 0

noim 0
nahid 0

one 10
two -10

Posted: Wed Jun 16, 2004 9:25 pm
by jagadish
my AC program gives the same output..but u hardly have any test cases :)

anyway let me know the output for this one
10
dave laura owen vick amr
dave2 laura2 owen2 vick2 amr2

dave 200 0
owen 500 1 dave
amr 150 2 vick owen
laura 0 2 amr vick
vick 0 0
dave2 200 0
owen2 500 1 dave
amr2 150 2 vick owen
laura2 0 2 amr vick
vick2 100 0





Posted: Wed Jun 16, 2004 9:56 pm
by jagadish
change this
while(scanf("%d",&nPerson)) to while(scanf("%d",&nPerson)==1) :)

Posted: Thu Jun 17, 2004 8:33 am
by WR
To jagadish:

Got your point!

Thanks a lot.

My program gives:

Code: Select all

dave 1000
laura 0
owen -350
vick 150
amr -150
dave2 0
laura2 0
owen2 -500
vick2 0
amr2 -150

119-Why WA??

Posted: Wed Jul 07, 2004 3:41 pm
by iyxm2000
#include "string.h"
#include "iostream.h"
#include "stdio.h"
class Person
{
public:
char name[13];
long in;
long out;
Person(char *s)
{
strcpy(name,s);
in=0;
out=0;
}
Person()
{
in=0;
out=0;
}
};

int main()
{
int n;
char temp[13];
while(cin>>n)
{
Person *givers=new Person[n];
for(int i=0;i<n;i++)
{
cin>>(givers+i)->name;
}
int outnum;
int tout;
for(int j=0;j<n;j++)
{
int x;
cin>>temp>>tout>>outnum;
int p;
for(p=0;p<n;p++)
{
if(!strcmp((givers+p)->name,temp))
{
(givers+p)->out+=tout;
x=p;
break;
}
}
for(int k=0;k<outnum;k++)
{
cin>>temp;
for(int l=0;l<n;l++)
{
if(!strcmp((givers+l)->name,temp))
{
(givers+l)->in=(givers+l)->in+tout/outnum;
break;
}
}
}
if(outnum!=0)
(givers+p)->out=((tout/outnum)*outnum);
}
for(int m=0;m<n;m++)
{
cout<<(givers+m)->name<<" "<<(((givers+m)->in)-((givers+m)->out))<<endl;
}
cout<<endl;
}

return 0;
}

Posted: Mon Jul 12, 2004 11:27 pm
by GreenPenInc
It might have something to do with the fact that you set the out field twice. On line 45 you update the total (although it's guaranteed to be zero, so you might as well clobber it) then around line 63 you actually do clobber it, but conditionally. If somebody were to give a nonzero amount of money to zero friends, you would no longer have a zero sum.

Or maybe it's because you use antiquated headers; I don't know.

119-Why WA?

Posted: Sat Jul 17, 2004 8:11 am
by Karthekeyan
Here's my code...Can someone help me find why I get wrong answer frm the Judge..

Code: Select all

[cpp]

#include<iostream>
#include<string>
using namespace std;
main()
{
  int n;
  while(cin>>n)
    {
      char names[10][13],name[10][13],giftto[10][10][13];
      int i,amount[10],ppl[10],j,profit[10],l,loss[i];
      for(i=0;i<n;i++)
	{
	  cin>>names[i];
	}
      for(i=0;i<n;i++)
	{
	  cin>>name[i]>>amount[i]>>ppl[i];
	  for(j=0;j<ppl[i];j++)
	    {
	      cin>>giftto[i][j];
	    }
	}
      for(i=0;i<10;i++)
	{
	  profit[i]=0;
	  loss[i]=0;
	}
      for(i=0;i<n;i++)
	{
	  for(j=0;j<ppl[i];j++)
	    {
	      for(l=0;l<n;l++)
		{
		  if(strcmp(name[l],giftto[i][j])==0)
		    {
		      profit[l]+=amount[i]/ppl[i];
		      loss[i]-=amount[i]/ppl[i];
		    }
		}
	    }
	}
      for(i=0;i<n;i++)
	{
	  profit[i]+=loss[i];
	}
      for(i=0;i<n;i++)
	{
	  for(j=0;j<n;j++)
	    {
	      if(strcmp(name[j],names[i])==0)
		  {
		    cout<<names[i]<<" "<<profit[j]<<'\n';
		  }
	    }
	}
      cout<<" ";      
    }

  return(0);
}
[/cpp]
Can someone atleast give me some sample i/o so that I find the mistake.

Posted: Sat Jul 17, 2004 11:07 am
by gibber
Your program has a mistake,please look at the tenth line of your program,you can't declare loss like this:" loss",it's not like vector.Just declare loss like this:" loss[10000]",you will get AC.Good lucky to you! :wink:(I'm not good at English,I hope you can understand what I say :oops: )

yeah...I changed that mistake...Yet it says WA for 119

Posted: Sat Jul 17, 2004 11:40 am
by Karthekeyan
Thanx a lot...But still it doesnt accept the prg.It still says it is a wrong answer...Pls,someone give me a sample i/o...

Posted: Sat Jul 17, 2004 12:55 pm
by Raiyan Kamal
Just take a look at the previous posts about this problem in this foruam. You will find a lot of sample I/O.

Its running on all the given i/o s

Posted: Sat Jul 17, 2004 1:04 pm
by Karthekeyan
Sorry Raiyan.

I hav checked with the i/os from this forum by checking with the board...
Thanx for ur concern....

119 - Greedy Gift Givers

Posted: Tue Sep 14, 2004 7:15 pm
by vadiu
I have read all the posts about this problem and tried all the "strange\special" cases and my program gives me good results. But when i submit it he gives me Wrong Answers. I can't understand why. :-? Any help would be greatly appreciated. Thanks...

[c]
#include "stdio.h"
#include "string.h"

void less();
void contabilizar();

int a, b, iterator, d, group, cash, number;
char giver[14];
char person[14];
FILE *in, *out;

struct pessoa{
int money;
char nome[10];
}list[10];

void less()
{
for(iterator=0; iterator<group; iterator++)
{
if(!strcmp(list[iterator].nome, giver))
{
if(cash==0)
break;
d=cash/number;
list[iterator].money-=d*number;
break;
}
}
}

int main()
{

in=stdin;
out=stdout;

while(fscanf(in, "%d", &group)!=EOF)
{

for(a=0; a<group;a++)
fscanf(in, "%s", &list[a].nome);

for(a=0; a<group; a++)
{
fscanf(in, "%s", giver);
fscanf(in, "%d %d", &cash, &number);

for(b=0; b<number; b++)
{
fscanf(in, "%s", person);
contabilizar();
}
if(number!=0)
less();
}

for(a=0; a<group; a++)
fprintf(out, "%s %d\n", list[a].nome, list[a].money);

for(a=0; a<group; a++)
list[a].money=0;

putchar('\n');

}

return 0;
}

void contabilizar()
{
for(iterator=0; iterator<group; iterator++)
{
if(!strcmp(list[iterator].nome, person))
{
list[iterator].money+=cash/number;
break;
}
}
}
[/c]

119-sample I/O

Posted: Wed Dec 15, 2004 9:27 am
by Zuberul
I cant find out why WA.
My code got Accepted on the usaco judge but wa here.
what is the case?
give me some sample I/O.