Page 1 of 10

Posted: Tue Dec 18, 2001 7:59 pm
by ..
In 119, there is sentence "Any money not given is kept and is part of a person's ``net worth'' printed in the output."

So, for the case,
1
mary
mary 20 0

I think the output is
mary 20

but the judge require us to output
mary 0

is the question requirement wrong??

Posted: Tue Jan 08, 2002 10:02 am
by bigredteam2000
No. The judges are right. Marry does not get anything because she does not receive presents.
The wording of this question is very misleading, though.

ACM 119

Posted: Wed Jul 03, 2002 6:10 am
by htl
Why doesn't this code get accepted?
It always gets WA
[c]
#include<stdio.h>
#include<string.h>
void main(void)
{
int n,money[10],x,givemoney,n2,receive,y;
char name[10][13],giver[13],receiver[10][13];
while(scanf("%d",&n)!=EOF)
{
for(x=0;x<n;x++)
scanf("%s",name[x]);
for(x=0;x<n;x++)
money[x]=0;
while(scanf("%s",giver)!=EOF)
{
scanf("%d",&givemoney);
scanf("%d",&n2);
if(!n2)
continue;
for(x=0;x<n2;x++)
scanf("%s",receiver[x]);
for(x=0;x<n;x++)
if(strcmp(giver,name[x])==0)
{
money[x]-=(givemoney-givemoney%n2);
break;
}
receive=(givemoney-givemoney%n2)/n2;
for(x=0;x<n2;x++)
for(y=0;y<n;y++)
if(strcmp(name[y],receiver[x])==0)
{
money[y]+=receive;
break;
}
}
for(x=0;x<n;x++)
printf("%s %d\n",name[x],money[x]);
}
}
[/c]

Posted: Wed Jul 03, 2002 10:24 am
by Picard
you can't use "while(scanf("%s",giver)!=EOF)"
there is exactly n lines of 'giver' data after the names.
btw you should put a blank line between each group in the output.

Posted: Wed Jul 03, 2002 11:48 am
by htl
The thing you said I don't understand:
btw you should put a blank line between each group in the output.
Could you explain it clearly?

Posted: Wed Jul 03, 2002 11:59 am
by Picard
"The output for each group should be separated from other groups by a blank line."

look at the sample output of the problem description, there is a blank line after "amr -150"

Posted: Wed Jul 03, 2002 12:04 pm
by htl
I put a '\n' after a group of output. And I got PE. I think it's because of the new line after each group. Maybe I don't have to put it. Thanks anyway.

Posted: Wed Jul 03, 2002 12:10 pm
by Picard
you shouldn't put a blank line after the last group (this is why i said only between groups)

Posted: Tue Jul 09, 2002 3:16 pm
by H-kun
I still cannot get my program to work. I think the problem is related to the input, because it takes really little time to fail. Could you send me sample input and output? Thank you.

119wa help

Posted: Thu Aug 29, 2002 8:04 am
by lu shukai
program P119;

{$APPTYPE CONSOLE}

uses
SysUtils;

type
mytype = record
name:array[1..15] of char;
len:integer;
money:integer;
end;
namet= record
name:array[1..15] of char;
len:integer;
end;
var
str:string;
i,n:integer;
people:array[1..15] of mytype;

procedure cal(giv,get:namet;m,nn:integer);
var
i,j:integer;
f:boolean;
begin
for i:=1 to n do
if people.len=get.len then begin
f:=true;
for j:= 1 to get.len do
if people.name[j]<>get.name[j] then begin
f:=false;
break;
end;
if f then break;
end;
people.money:=people.money+m div nn;
end;


procedure setmoney(str:string);
var
i,t,c,m,nn,j:integer;
giv,get:namet;
f:boolean;
begin
t:=1;
while not((str[t]>='a')and(str[t]<='z')) do
t:=t+1;
i:=0;
while (str[t]>='a')and(str[t]<='z') do begin
i:=i+1;
giv.name:=str[t];
t:=t+1;
end;
giv.len:=i;
while not((str[t]>='0')and(str[t]<='9')) do
t:=t+1;
m:=0;
while (str[t]>='0')and(str[t]<='9') do begin
m:=m*10+ord(str[t])-48;
t:=t+1;
end;
while not((str[t]>='0')and(str[t]<='9')) do
t:=t+1;
nn:=0;
while (str[t]>='0')and(str[t]<='9') do begin
nn:=nn*10+ord(str[t])-48;
t:=t+1;
end;
if (m<>0)and(nn<>0) then begin
for j:= 1 to nn do begin
while not((str[t]>='a')and(str[t]<='z')) do
t:=t+1;
i:=0;
while (str[t]>='a')and(str[t]<='z') do begin
i:=i+1;
get.name:=str[t];
t:=t+1;
end;
get.len:=i;

cal(giv,get,m,nn);
end;
for i:=1 to n do
if people.len=giv.len then begin
f:=true;
for j:= 1 to giv.len do
if people.name[j]<>giv.name[j] then begin
f:=false;
break;
end;
if f then break;
end;
people.money:=people.money-(m div nn)*nn;
end;



end;


procedure setname(str:string);
var
j,i,le,c,t:integer;
begin
t:=1;
c:=0;
while c<n do begin
c:=c+1;
while not((str[t]>='a')and(str[t]<='z')) do
t:=t+1;
le:=0;
while (str[t]>='a')and(str[t]<='z') do begin
le:=le+1;
people[c].name[le]:=str[t];
t:=t+1;
end;
people[c].len:=le;
end;
end;

procedure slv;
var
i,j:integer;
begin
for i:= 1 to n do begin
for j:= 1 to people[i].len do
write(people[i].name[j]);
write(' ');
writeln(people[i].money);
end;
end;

begin
while not eof do begin
readln(n);
readln(str);
setname(str);
for i:= 1 to n do
people[i].money:=0;
for i:=1 to n do begin
readln(str);
setmoney(str);
end;
slv;
writeln;
end;
end.

119 : GG Giver - Problem with multiple input

Posted: Sat Sep 14, 2002 9:34 pm
by laboni
Hey!
My program solves the problem correctly but it does not take more than one input.It takes only the first set of input, gives correct result, but then exist. Can u plz find out why?
here is the code in C:
[c]

//greedy gift giver:119

#include<stdio.h>
#include<string.h>

char name[100][200];
long balance[1000];
char t[150];

void main()
{
long x,i,j,k,m,people=0,per,h;
long n; char dummy;

while(scanf("%ld",&n)==1){
for(i=0;i<n;i++)
{
scanf("\n%s",name);
balance=0;
};
for(i=0;i<n;i++)
{
//m=total gifted money by t
scanf("\n%s%ld%ld",t,&m,&people);
//people=peoples to be gifted
if(!m || !people) continue;
per = m/people;
//per= perhead money to be gifted
x = m - per*people;

for(k=0;k<n;k++)
{
if (strcmp(t,name[k])==0)
{
balance[k] += x;
balance[k] -= m;
break;
}

} ; //end of for k
scanf("%c",&dummy);
for(j=0;j<people;j++)
{
scanf("%s",t);
for(k=0;k<n;k++)
{
if (strcmp(t,name[k])==0)
balance[k] += per;
} //end of for k
} //end of for j
} //end of for big i
scanf("%c",&dummy);
//printing
for(i=0;i<n;i++)
printf("%s %ld\n",name,balance);
printf("\n");
} //end of while
} //end of main

[/c]
Hope some one would help me :-?

Posted: Sat Sep 14, 2002 11:21 pm
by Yarin
Your input reading routine seems dangerous. Try this one instead:
while (!feof(stdin)) {
scanf("%d\n",&n);
for(i=0;i<n;i++)
scanf("%s",names);
for(i=0;i<n;i++) {
scanf("%s %d %d",s,&amount,&k);
....
for(j=0;j<k;j++) {
scanf("%s",s);
...
}
....
scanf("\n");
}
}

Posted: Sun Sep 15, 2002 5:44 pm
by laboni
I read everything with gets & got AC now.
still thanks for your advice.

Posted: Sat Nov 16, 2002 10:57 am
by supermin
Picard wrote:you shouldn't put a blank line after the last group (this is why i said only between groups)

Code: Select all

#include<stdio.h>
#include<string.h>

int main(void)
{
 int n_people,i,j,count;
 char name[10][13],cmp[13],host[13];
 int money[10],cash;
 int give_n;
 
 while(scanf("%d",&n_people)!=EOF)
 {
  
  for(i=0;i<10;i++)
	  money[i]=0;

  i=0;
  while(i<n_people) 
  {
	  scanf("%s",name[i]);
      i++;
  }

  count=0;
  while(count<n_people)
  {
	  scanf("%s %d %d",host,&cash,&give_n);
      if(give_n==0) 
	  {
		  count++;	
          continue;
	  }
	  i=0;
	  while(i<give_n) 
	  {
	   scanf("%s",cmp);
	   for(j=0;j<n_people;j++)
	   if(strcmp(cmp,name[j])==0) money[j]+=cash/give_n;
	   i++;
	  }
	  for(j=0;j<n_people;j++)
		  if(strcmp(host,name[j])==0) money[j]+=cash%give_n-cash;
	  count++;
  }

  
  for(i=0;i<n_people;i++)
  {
   printf(name[i]);
   printf(" %d\n",money[i]);
  }
  
 }
 
 return 0;
}
I think for a while.....but I still can't figure out how to do the "blank line" except the last group..
Could you help me motify my source code....thanx
(I also got the P.E. accepted)[/c]

Posted: Wed Nov 20, 2002 4:57 am
by Olorin
Supermin: my dumb $0.02:
I think for a while.....but I still can't figure out how to do the "blank line" except the last group..
Put a blank line before every group except the first?

Just a hint, HTH