Ho buttato giù un po di codice, dovrebbe fare il suo lavoro
codice:#include <stdio> #include <stdlib> #define VECTORLEN 10 typedef struct { int value; int count; } tPair; void sortByValue( tPair *pair, int length ) { int i; tPair tmp; for( i=0; i<length-1; i++) { if( pair[i].value > pair[i+1].value ) { tmp = pair[i]; pair[i] = pair[i+1]; pair[i+1] = tmp; i=-1; } } } int bCheckMatch( const int *x, const int maxLenX, const int *y, const int maxLenY ) { tPair cx[VECTORLEN]; tPair cy[VECTORLEN]; int i, j, cx_max = 0, cy_max = 0; for( i=0; i<VECTORLEN; i++ ) { cx[i].value = 0; cx[i].count = 0; cy[i].value = 0; cy[i].count = 0; } for( i=0; i<maxLenX; i++ ) { for( j=0; j<VECTORLEN && cx[j].value != x[i] && j<cx_max; j++ ); cx[j].value = x[i]; // Inserisce il valore corrente cx[j].count ++; // Incrementa il contatore del valore corrente if( j>=cx_max ) cx_max ++; } for( i=0; i<maxLenY; i++ ) { for( j=0; j<VECTORLEN && cy[j].value != y[i] && j<cy_max; j++ ); cy[j].value = y[i]; // Inserisce il valore corrente cy[j].count ++; // Incrementa il contatore del valore corrente if( j>=cy_max ) cy_max ++; } sortByValue( cx, cx_max ); sortByValue( cy, cy_max ); if( cx_max != cy_max ) return 0; for( i=0; i<cx_max; i++ ) if( cx[i].value != cy[i].value || cx[i].count != cy[i].count ) return 0; return 1; }

Rispondi quotando
