All pastes #762393 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-05 17:20 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char grille0[500][501];
char mots0[500][501];
int N,M,P;

int trouve_mots() {
	// à compléter
	int i, j, l, r = 0;
	char grille1[500][501];
	char mots1[500][501];
	char* utilisable = malloc( sizeof( char ) * P );
		if( utilisable == NULL ) exit( 1 );
	
	//	Mots inversés
	for( i = 0; i < P; i ++ ) {
		utilisable[i] = 1;
		l = strlen( mots0[i] ) - 1;
		for( j = 0; j <= l; j ++ ) {
			mots1[i][l - j] = mots0[i][j];
		}
		//	Élimination des mots en double
		for( j = 0; j < P && utilisable[i]; j ++ ) {
			if( !strcmp( mots0[i], mots0[j] ) && i != j && utilisable[j] ) {
				utilisable[i] = 0;
			}
		}
		mots1[i][j] = '\0';
	}
	//	Grille inversée XY
	for( i = 0; i < N; i ++ ) {
		for( j = 0; j < M; j ++ ) {
			grille1[j][i] = grille0[i][j];
		}
		grille1[j][N] = '\0';
	}
	
	//	H = horizontale, V = verticale, I = inversé
	for( i = 0; i < P; i ++ ) {
		for( j = 0; ( j < N || j < M ) && utilisable[i]; j ++ ) {
			if( strstr( grille0[j], mots0[i] ) != NULL || 	//	H
				strstr( grille0[j], mots1[i] ) != NULL || 	//	HI
				strstr( grille1[j], mots0[i] ) != NULL || 	//	V
				strstr( grille1[j], mots1[i] ) != NULL ) {	//	VI
				r ++;
				utilisable[i] = 0;
			}
		}
	}

	return r;
}

int main()
{
  int i,j;
  scanf("%d%d%d",&N,&M,&P);
  getchar();
  for (i=0 ; i < P ; i++)
    scanf("%s",mots0[i]);
  getchar();
  for (i=0 ; i < N ; i++) {
    for (j=0 ; j < M ; j++) {
      grille0[i][j] = getchar();
    }
    getchar();
  }
  printf("%d\n", trouve_mots());
  return 0;
}