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;
}
#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;
}
相关文章推荐
- poj1035 Spell checker
- poj 1035 Spell checker
- 【POJ】1035 Spell checker
- poj 1035 Spell checker
- poj1035 Spell checker
- POJ 1035 Spell checker
- poj 1035 Spell checker
- POJ1035——Spell checker
- poj1035 Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- poj-1035--Spell checker-串
- poj-1035 Spell checker
- POJ1035 Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- POJ 1035 Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- POJ 1035 Spell checker