poj 1035 Spell checker

http://poj.org/problem?id=1035

题意:给出一些字典单词,然后给出查询的单词temp,若字典单词中有temp就直接输出,如果没有就输出1:一个字母拼写错误;2:多添加了 一个字母;3:少了一个字母;

思路:用vector存的string序列,然后用string的一些特性来判断的;

代码:

View Code
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
vector<string>vec;
string temp;
int biao = 0;
void work(string a,string b)
{
int len = a.length();
int count = 0;
for(int i = 0;i < len; ++i)
{
if(a[i] != b[i])
count++;
if(count > 1)
return ;
}
cout<<" "+a;
}
void work1(string a,string b,int q)
{
int len = 0;
len = b.length();
for(int i = 0;i < len; ++i)
{
if(a[i] != b[i])
{
string temp = a;
temp.erase(i,1);
if(b == temp)
{
if(q)
cout<<" "+a;
else
cout<<" "+b;
}
return ;
}
}
if(q)
cout<<" "+a;
else
cout<<" "+b;
}
int main()
{
//freopen("input.txt","r",stdin);
while(1)
{
cin>>temp;
if(temp == "#")
break;
vec.push_back(temp);
}

while(1)
{
int biao = 0;
cin>>temp;
if(temp == "#")
break;
int len1 = vec.size();
int len = temp.length();
for(int i = 0;i < len1;++i)
if(vec[i] == temp)
{
biao = 1;
cout<<temp+" is correct"<<endl;
break;
}
if(biao)
continue;
cout<<temp+":";
int le = 0;
for(int i = 0;i < len1; ++i)
{
le = vec[i].length();
if(le == len)
work(vec[i],temp);
else
if(le == len +1)
work1(vec[i],temp,1);
else
if(len == le + 1)
work1(temp,vec[i],0);
}
cout<<endl;
}
return 0;
}



转载于:https://www.cnblogs.com/LT-blogs/archive/2012/03/25/2416740.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值