ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1089. Verification with the Dictionary

this works!
Posted by Marcin Mika 7 Feb 2003 05:27
#include <stdio.h>
#include <string.h>
#include <ctype.h>
FILE *in,*out;

char words[1000][100];
char data[10000];
char temp[5120];

int match( int k ){
 int d=0;
  int f=0;

   while ( temp[f] ){
    if ( words[k][f]!=temp[f] ) d++;
     if ( d>1 )
      return 0;
       f++;
   }
    return d==1;
}

void main( void ){
//in=fopen( "input.txt", "r" );
in=stdin;
out=stdout;

//char temp[512];
int i,j,k;
i=0;
while ( 1 ){
 fscanf( in, "%s", temp );
  if ( temp[0]=='#' )
   break;
  strcpy( words[i], temp );
  i++;
}

j=0;
fgetc(in);
while ( !feof(in) )
  data[j++]=fgetc(in);
j-=2;
data[j]=0;
///j-=2;

int ncorrect=0;
int p;

for ( k=0; k<j; k++ ){

  while ( ispunct(data[k]) )
   k++;
    p=0;
     while ( k<j && isalpha(data[k]) )
      temp[p++]=data[k++];
     temp[p]=0;
      int c;
 for ( c=0; c<i; c++ )
  if ( strlen(words[c])==p )
   if ( match(c) ){
    memcpy( &data[k-p],words[c],p );
    ncorrect++;
   }
 }

  for ( k=0; k<j; k++ )
   fputc( data[k], out );
 fprintf( out, "\n%d\n", ncorrect );

}