Poj Solution 1147

http://poj.org/problem?id=1147

#include"stdio.h"
int a[3001];
int next[3001];
int main()
{
    int n,i,j,k=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(!a[i])k++;
    }
 j=1; k++;
    for(i=1;i<=n;i++)
  if(a[i])
  { next[k]=i; k++; }
  else
  { next[j]=i; j++; }
    k=1;
    for(i=1;i<=n;i++)
    {
        k=next[k];
        printf("%d ",a[k]);
    }
 return 0;
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *