标签:
#include<iostream>
#include<stdio.h>
#define MAXN 10001
using namespace std;
char dict[MAXN][20];
char s[20];
bool is_replace(const char * a,const char * b);
bool is_delete(const char * a,const char * b);
bool is_add(const char * a,const char * b);
int main()
{
//freopen("acm.acm","r",stdin);
int i = 0;
int j = 0;
while(cin>>dict[i],dict[i][0] != ‘#‘)
{
++ i;
}
while(cin>>s,s[0] != ‘#‘)
{
for(j = 0; j < i; ++ j)
{
if(strcmp(s,dict[j]) == 0)
{
cout<<s<<" is correct"<<endl;
break;
}
}
if(j == i)
{
cout<<s<<": ";
for(j = 0; j < i; ++ j)
{
if(is_replace(s,dict[j]) || is_add(s,dict[j]) || is_delete(s,dict[j]))
{
cout<<dict[j]<<" ";
}
}
cout<<endl;
}
else
{
continue;
}
}
}
bool is_replace(const char * a,const char * b)
{
int len_a = strlen(a);
int len_b = strlen(b);
int i;
int j;
int count = 0;
if(len_a == len_b)
{
for(i = 0,j = 0; i < len_a;)
{
if(a[i] == b[j])
{
++ i;
++ j;
}
else
{
++ i;
++ j;
++ count;
}
if(count > 1)
return false;
}
}
else
{
return false;
}
return true;
}
bool is_delete(const char * a,const char * b)
{
int len_a = strlen(a);
int len_b = strlen(b);
int i;
int j;
int count = 0;
if(len_a + 1 == len_b)
{
for(i = 0,j = 0; j < len_b;)
{
if(a[i] == b[j])
{
++ i;
++ j;
}
else
{
++ j;
++ count;
}
if(count > 1)
{
return false;
}
}
}
else
{
return false;
}
return true;
}
bool is_add(const char * a,const char * b)
{
int len_a = strlen(a);
int len_b = strlen(b);
int i;
int j;
int count = 0;
if(len_a == len_b + 1)
{
for(i = 0,j = 0; i < len_a;)
{
if(a[i] == b[j])
{
++ i;
++ j;
}
else
{
++ i;
++ count;
}
if(count > 1)
{
return false;
}
}
}
else
{
return false;
}
return true;
}
标签:
原文地址:http://www.cnblogs.com/gavinsp/p/4563225.html