POJ-1035 - 字符串-暴力

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

题意:

给出一个字典。

给出一系列单词,让你在字典匹配

如果存在,输出 字符串  is correct

否则,看能否找到 以下三种近似单词:
1同长度,只有一个位置不同
2长度-1,其余相同
3长度+1,除了那个+1的字符,其余相同
输出所有的类似单词
否则 输出原单词+空行


官方参考代码真是思路清晰,简洁啊。。。。自己之前写的简直是@#¥%¥…………¥%#



#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std; 
const int mod=1000000007;
int min(int a,int b)
{return a<b?a:b;}
int max(int a,int b)
{return a>b?a:b;}

 char tm[10005][20];
 
int can_replace(char *in,char *orig,int len)
{
	int i;
	int len2=strlen(orig);
		i=0;
	if (len==len2)
	{
		while(i<len2&&in[i]==orig[i])
			i++;
		while(++i<len2)
			if (in[i]!=orig[i]) return 0;
	}
	else  if (len==len2-1)
	{ 
		while(i<len2&&in[i]==orig[i])
			i++;
		while(++i<len2)
			if (in[i-1]!=orig[i]) return 0;
	}
	else if (len==len2+1)
	{
		while(i<len&&in[i]==orig[i])
			i++;
		while(++i<len)
			if (in[i]!=orig[i-1]) return 0;
	}
	else return 0;
	
	return 1;
}
int main()
{
 //	 freopen( "F:\\duipai\\1.out","w",stdout ); 
	char tmp[20];
	int j,i;
	int ok=0;
	while(scanf("%s",tm[++ok])!=EOF)
	{
		if (strcmp(tm[ok],"#")==0)break;
	}
ok--;
 		while(scanf("%s",tmp)!=EOF)
	{
		 if (strcmp(tmp,"#")==0)break;
		 int len=strlen(tmp);
		 int flag=0;
		 for (i=1;i<=ok;i++)
		 {
			 if (strcmp(tmp,tm[i])==0)
			 {
				 flag=1;break;
			 }
		 }
		 if (flag)
			printf("%s is correct\n",tmp);
		 else
		 {
			 printf("%s:",tmp);
			 for (j=1;j<=ok;j++)
			 {
				 if (can_replace(tmp,tm[j],len))
				 printf(" %s",tm[j]);
			 }
			 printf("\n");
		 }

	}


	return 0;
	
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值