402 - M*A*S*H
Moderator: Board moderators
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
402 WA
Can anyone tell me why my program gets WA?
[pascal]Program p402;
Const MaxN = 100;
Var Inf,Card : Array[1..MaxN]of Integer;
N,X,i,j : Integer;
T,left,k : Integer;
begin
T:=0;
While Not Eof(InPut) Do begin
T:=T+1;
if T>1 then Writeln;
Writeln('Selection #',T);
Read(N,X);
for i:=1 to 20 do Read(Card);
left:=N;
for i:=1 to N do Inf:=0;
for i:=1 to 20 do begin
if left<=X then Break;
k:=0;
for j:=1 to N do begin
if Inf[j]=0 then begin
k:=k+1;
if k mod Card=0 then begin
Inf[j]:=1;
left:=left-1;
if left<=X then Break;
end;
end;
end;
end;
for i:=1 to N do
if Inf=0 then
Write(i,' ');
Writeln;
end;
end.[/pascal]
[pascal]Program p402;
Const MaxN = 100;
Var Inf,Card : Array[1..MaxN]of Integer;
N,X,i,j : Integer;
T,left,k : Integer;
begin
T:=0;
While Not Eof(InPut) Do begin
T:=T+1;
if T>1 then Writeln;
Writeln('Selection #',T);
Read(N,X);
for i:=1 to 20 do Read(Card);
left:=N;
for i:=1 to N do Inf:=0;
for i:=1 to 20 do begin
if left<=X then Break;
k:=0;
for j:=1 to N do begin
if Inf[j]=0 then begin
k:=k+1;
if k mod Card=0 then begin
Inf[j]:=1;
left:=left-1;
if left<=X then Break;
end;
end;
end;
end;
for i:=1 to N do
if Inf=0 then
Write(i,' ');
Writeln;
end;
end.[/pascal]
read previous mailing
Why do you open a third thread on 402?
If you had read the previous threads, you could have found the answer.
One additional note:
you don't read line-breaks, so if there is a line-break after the last line in the inputfile, your program won't be able to detect the eof.
Another additional note:
If you had read the previous threads, you could have found the answer.
One additional note:
you don't read line-breaks, so if there is a line-break after the last line in the inputfile, your program won't be able to detect the eof.
Another additional note:
The list of ``lucky" positions is then followed by a blank line.
WA Still
My programs response:
I don't understand the problem. Can anyone help me?
Input:
10 2 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
47 6 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
31 9 5 8 2 1 7 7 11 3 6 5 4 9 10 5 2 1 5 3 9 7
16 3 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
25 1 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
3 2 3
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
Output:
Selection #1
1 8
Selection #2
1 3 16 23 31 47
Selection #3
6 8 12 14 17 21 23 26 28
Selection #4
1 3 16
Selection #5
1 2 3 4 5 6 11 19
Selection #6
1 2 3 4 5 6 7 8 9 10
Selection #7
1 2
Selection #8
1 2 3 4 5 6 7 8 9 10

I don't understand the problem. Can anyone help me?

Input:

10 2 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
47 6 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
31 9 5 8 2 1 7 7 11 3 6 5 4 9 10 5 2 1 5 3 9 7
16 3 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
25 1 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
3 2 3
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
Output:

Selection #1
1 8
Selection #2
1 3 16 23 31 47
Selection #3
6 8 12 14 17 21 23 26 28
Selection #4
1 3 16
Selection #5
1 2 3 4 5 6 11 19
Selection #6
1 2 3 4 5 6 7 8 9 10
Selection #7
1 2
Selection #8
1 2 3 4 5 6 7 8 9 10
The 2nd laziest person of the world
What to do then
But if the Judge Input is ok my program should work.
[c]
/*@begin_of_source_code*/
/* @JUDGE_ID: 13965AB 402 C*/
#include<stdio.h>
int people[51], remain, total, stop;
void init(){
for(int x=0;x<50;x++)
people[x]=1;
remain=0;total=0;
stop=0;
}
void main(){
int n,x,cur,f, count,c=0, space=0, cont;
#ifndef ONLINE_JUDGE
freopen("c:\\tcwin\\bin\\402.in","rt",stdin);
freopen("c:\\tcwin\\bin\\402.out","wt",stdout);
#endif
while(scanf("%d%d",&n,&x)==2){
if(c>0) printf("\n\n");
init();
if(x>n || n<=0 || x==0){
c++;
printf("Selection #%d\n",c);
space=0;
for(f=0;f<n;f++){
if(space) printf(" ");
printf("%d",f+1);
space++;
}
}
else{
total=n; stop=x; remain=n;
cont=0;
while(remain>stop){
if(cont>=20) break;
scanf("%d",&cur);
cont++;
count=0;
for(f=0;f<total;f++){
if(people[f]) count++;
if (count==cur){
if(remain<=stop) break;
people[f]=0;
remain--;
count=0;
}
}
}
c++;
printf("Selection #%d\n",c);
space=0;
for(f=0;f<total;f++)
if(people[f]){
if(space>0)printf(" ");
printf("%d",f+1);
space++;
}
}
char *st;
scanf("%[^\n]%c",st);
}
}
/*@end_of_source_code*/
[/c]
[c]
/*@begin_of_source_code*/
/* @JUDGE_ID: 13965AB 402 C*/
#include<stdio.h>
int people[51], remain, total, stop;
void init(){
for(int x=0;x<50;x++)
people[x]=1;
remain=0;total=0;
stop=0;
}
void main(){
int n,x,cur,f, count,c=0, space=0, cont;
#ifndef ONLINE_JUDGE
freopen("c:\\tcwin\\bin\\402.in","rt",stdin);
freopen("c:\\tcwin\\bin\\402.out","wt",stdout);
#endif
while(scanf("%d%d",&n,&x)==2){
if(c>0) printf("\n\n");
init();
if(x>n || n<=0 || x==0){
c++;
printf("Selection #%d\n",c);
space=0;
for(f=0;f<n;f++){
if(space) printf(" ");
printf("%d",f+1);
space++;
}
}
else{
total=n; stop=x; remain=n;
cont=0;
while(remain>stop){
if(cont>=20) break;
scanf("%d",&cur);
cont++;
count=0;
for(f=0;f<total;f++){
if(people[f]) count++;
if (count==cur){
if(remain<=stop) break;
people[f]=0;
remain--;
count=0;
}
}
}
c++;
printf("Selection #%d\n",c);
space=0;
for(f=0;f<total;f++)
if(people[f]){
if(space>0)printf(" ");
printf("%d",f+1);
space++;
}
}
char *st;
scanf("%[^\n]%c",st);
}
}
/*@end_of_source_code*/
[/c]
Last edited by manir on Sun Jul 14, 2002 2:03 am, edited 1 time in total.
The 2nd laziest person of the world
the problem is:
1. you pass an unassigned char* pointer for %[^\n]
2. you don't pass parameter for %c
Code: Select all
char *st;
scanf("%[^\n]%c",st);
2. you don't pass parameter for %c
Thanks.
But I still get a nice WA.
But I still get a nice WA.
Last edited by manir on Sun Jul 14, 2002 2:16 am, edited 1 time in total.
The 2nd laziest person of the world