Practice>>Easy>>Ambiguous Permutations

WHY THIS CODE SHOWS RUNTIME ERROR?

---------------------------------------------
/* Ambiguous permutations */
#include<stdio.h>
int main()
{ int a[6],b[6],i=0,j,t,m;
/*Test Cases*/

while(1)
{ scanf("%d",&t);

if(t==0)
break;
else
{ m=t;/*Act as a future counter*/
    for(i=1;i<=t;i++)
    {
                     scanf("%d",&a[i]);
   /*INVERSE permutation formation*/
       j=a[i];
       b[j]=i;
}

for(i=1;i<=t;i++)
{ if(a[i]!=b[i])
break;
}
if(i==m+1)
printf("ambiguous\n");
else
printf("not ambiguous\n");
} 
}

return 0;
}
------------------------------------------------

Here it is - http://ideone.com/Lby9rZ

Without the RE it prints a lot, it should print (input.lines/2) lines, so in my input there are 3 lines, I’d expect just one line as a result.

1 Like
//