poj1035(简单题,串)

  一个简单题,先看字典中是否存在该传,如果不存在,就跟字典中字符串的长度比较,长度的绝对差大于1时,必定不是候选的答案串,长度相等时,看是否只有一个字符错误;长度不等时,看是否可以通过较长串删除一个字符得到较短串。

  

#include "stdio.h"
#include "string.h"
#include "math.h"
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;

#define MAXM 1
#define MAXN 10005
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b
#define abs(a)  a < 0 ? a : (-a)
#define Mem(a,b) memset(a,b,sizeof(a))
int Mod = 1000000007;
double pi = acos(-1.0);
double eps = 1e-6;

char dic[MAXN][20];

typedef struct{
	int f,t,w,next;
}Edge;
Edge edge[MAXM];
int head[MAXN];
int kNum;

void addEdge(int f, int t, int w)
{
	edge[kNum].f = f;
	edge[kNum].t = t;
	edge[kNum].w = w;
	edge[kNum].next = head[f];
	head[f] = kNum ++;
}

char s[20];

void work( )
{
	for(int i = 0; i < kNum; i ++){
		if( strcmp(s, dic[i]) == 0 ){
			printf("%s is correct\n",s);
			return;
		}
	}

	printf("%s:",s);

	int len1 = strlen(s), len2;

	for(int i = 0; i < kNum; i ++){
		len2 = strlen(dic[i]);
		if( len1 == len2 ){
			int count = 0;
			for(int j = 0; j < len1; j ++){
				if( s[j] != dic[i][j] ){
					count ++;
					if( count > 1 ) break;
				}
				if( j == len1 - 1 )
					printf(" %s",dic[i]);
			}
		}

		else if( len1 - len2 == 1 ){
			int j,k;
			int count = 0;
			for( j = 0, k = 0; j < len1; j ++){
				if( s[j] != dic[i][k] ){
					count ++;
					if( count > 1 ) break; 
				}
				else
					k ++;
				if( j == len1 - 1 )
					printf(" %s", dic[i]);
			}
		}

		else if( len2 - len1 == 1 ){
			int j,k;
			int count = 0;
			for( j = 0, k = 0; j < len2; j ++){
				if( dic[i][j] != s[k] ){
					count ++;
					if( count > 1 ) break; 
				}
				else
					k ++;
				if( j == len2 - 1 )
					printf(" %s", dic[i]);
			}
		}
	}
	printf("\n");
}

void solve()
{
	kNum = 0;
	if( strcmp(s,"#") == 0 ) return;

	do{
		getchar();
		if( strcmp(s,"#") == 0 )
			break;
		strcpy(dic[kNum++],s);
	}while(cin>>s);

	while(cin>>s){
		if( strcmp(s, "#") == 0 )
			break;
		work();
	}
}


int main()
{
//	freopen("d:\\test.txt", "r", stdin);
	while(cin>>s){
		solve();
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值