#include<stdio.h>
int scrambled( unsigned int a[], unsigned int b[], unsigned int len )
{
int x, y;
unsigned int score1 = 0;
unsigned int score2 =0;
int scramble = 1;
if( len !=0){
for (x=0; x<len; x++){
for (y=0; y < len; y++){
if (b[y] == a[x]){
score1++;
break;
}
}
}
for (x=0; x<len; x++){
for (y=0; y < len; y++){
if (a[y] == b[x]){
score2++;
break;
}
}
}
}
if( (score1 != len) || (score2 != len) ){
scramble = 0;
}
return scramble;
}
int main( void )
{
unsigned int a[5] = {0,5,4,1,2} ;
unsigned int b[5] = {1,2,0,4,5};
if( scrambled( a, b, 5 ) == 1 )
{
printf( "b is a scrambled version of a\n" );
} else {
printf( "b has different contents to a\n" );
}
return 0;
}
No comments:
Post a Comment