您的位置:首页 > 其它

POJ 1035 Spell checker

2012-07-17 17:22 369 查看
#include<iostream>

#include<cstring>

using namespace std;

void sreplace(char sample[],char dictionary[])

{

int count=0;

for(int j=0;j<strlen(dictionary);j++)

{

if(dictionary[j]!=sample[j]) count++;

}

if(count==1) cout<<" "<<dictionary;

}

void sinsert(char sample[],char dictionary[])

{

int j,k=0;

for( j=0;j<strlen(dictionary);)

{

if(sample[k]==dictionary[j]) j++,k++;

else j++;

}

if(k==strlen(sample)) cout<<" "<<dictionary;

}

void serase(char sample[] ,char dictionary[])

{

int j,k=0;

for( j=0;j<strlen(sample);)

{

if(sample[j]==dictionary[k]) j++,k++;

else j++;

}

if(k==strlen(dictionary)) cout<<" "<<dictionary;

}

int main()

{

char dict[10001][16];

char sample[16];

int i=0,j,nbool;

while(i+1)

{

cin>>dict[i];

if(strcmp(dict[i],"#")==0) break;

i++;

}

while(cin>>sample)

{

if(strcmp(sample,"#")==0) break;

nbool=0;

for(j=0;j<i;j++)

if(strcmp(sample,dict[j])==0)

{

cout<<sample <<" is correct\n";

nbool=1;

break;

}

if(nbool==0)

{

cout<<sample<<":";

for(j=0;j<i;j++)

{

if(strlen(sample)==strlen(dict[j]))

{

sreplace(sample,dict[j]);

}

if(strlen(sample)==strlen(dict[j])-1)

{

sinsert(sample,dict[j]);

}

if(strlen(sample)==strlen(dict[j])+1)

{

serase(sample,dict[j]);

}

}

cout<<endl;

}

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: