Sign of permutations by rolf

#include <stdio.h>
int main(){char*l=malloc(99),*x;int P[99],I,i,j,s;while(getline(&l,&I,stdin)>0){I=i=0;while(x=strtok(l," "))l=0,P[I]=atoi(x),I++;s=1;for(;i<I;i++)if((j=i+1)!=P[i]){for(;P[j]!=i+1;j++);P[j]=P[i];s=-s;}printf("%d\n",s);}}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

To protect the system from spam, please input your favorite sport (hint: I believe its name must start with 'g', case insensitive)

download

return to the top page