|
|
вернуться в форумI see,it's a bug!!!remove the newline character!!!!! #include<stdio.h> void main() { int i,j,n,p,map[101][101],seq[101],in[101],head,tail; scanf("%d",&n); for(i=1;i<=n;i++) for(j=1;j<=n;j++) map[i][j]=0; for(i=1;i<=n;i++) { scanf("%d",&p); while(p) { map[i][p]=1; scanf("%d",&p); } } for(i=1;i<=n;i++) { in[i]=0; for(j=1;j<=n;j++) if(j!=i&&map[j][i]) in[i]++; } head=tail=0; do { for(i=1;i<=n;i++) { if(in[i]==0) { in[i]=-1; seq[tail++]=i; } } while(head<tail) { for(j=1;j<=n;j++) if(seq[head]!=j&&map[seq[head]][j]&&in[j]!=-1) in[j]--; head++; } }while(tail<n); for(i=0;i<n-1;i++) printf("%d ",seq[i]); printf("%d",seq[i]); } The standard output should contain in its ONLY line > #include<stdio.h> > void main() > { int i,j,n,p,map[101][101],seq[101],in[101],head,tail; > scanf("%d",&n); > for(i=1;i<=n;i++) > for(j=1;j<=n;j++) > map[i][j]=0; > > for(i=1;i<=n;i++) > { scanf("%d",&p); > while(p) > { map[i][p]=1; > scanf("%d",&p); > } > } > > for(i=1;i<=n;i++) > { in[i]=0; > for(j=1;j<=n;j++) > if(j!=i&&map[j][i]) in[i]++; > } > > head=tail=0; > do > { for(i=1;i<=n;i++) > { if(in[i]==0) > { in[i]=-1; > seq[tail++]=i; > } > } > while(head<tail) > { for(j=1;j<=n;j++) > if(seq[head]!=j&&map[seq[head]][j]&&in[j]!=-1) > in[j]--; > head++; > } > }while(tail<n); > > for(i=0;i<n-1;i++) > printf("%d ",seq[i]); > printf("%d",seq[i]); > > > > } > Yeah, it's a strange bug. |
|
|