Poj 1035

这道题搞得还真不容易,一个=跟==,搞了自己近两个钟头。。。

用的是暴搜解决

 

 

/* Poj 1035, by Dream 2011/4/28 */

#include <iostream>

using namespace std;

 

char dic[10010][20];

unsigned int totalNo = 0;

void DealWord(const char *word);

int CalculateValue(const char* word1, const char*word2);

 

int main()

{

freopen("input.txt","r",stdin);

char tmpword[20];

totalNo = 0;

while(EOF != scanf("%s",tmpword))

{

if ('#' == tmpword[0])

{

break;

}

strcpy(dic[totalNo], tmpword);

++totalNo;

}

 

while(EOF != scanf("%s", tmpword))

{

if ('#' == tmpword[0])

{

break;

}

DealWord(tmpword);

}

return 0;

}

 

 

 

int CalculateValue(const char* word1, const char*word2)

{

int m = strlen(word1);

int n = strlen(word2);

int i = 0; 

/* replace one word */

if (m == n)

{

while((i < m) && (word1[i] == word2[i]))

++i;

while(++i < m)

{

if (word1[i] != word2[i])

{

return 0;

}

}

}

else if (m == n + 1)             //这里写成了if(m=n+1),悲剧

{

while((i < n) && (word1[i] == word2[i]))

++i;

while(++i < m)

{

if (word1[i] != word2[i-1])

{

return 0;

}

}

}

else if (m + 1 == n)

{

while((i < m) && (word1[i] == word2[i]))

++i;

while(++i < n)

{

if (word1[i - 1] != word2[i])

{

return 0;

}

}

}

 

else

{

return 0;

}

return 1;

}

void DealWord(const char *word)

{

unsigned int res = 0;

unsigned int crntMin = 10000;

bool bFound = false;

for (unsigned int i = 0; i < totalNo; ++i)

{

if (!strcmp(word, dic[i]))

{

bFound = true;

}

}

if (bFound)

{

printf("%s is correct/n", word);

return;

}

else

{

printf("%s:", word);

}

for (unsigned int i = 0; i < totalNo; ++i)

{

if (CalculateValue(word, dic[i]))

{

printf(" %s", dic[i]);

}

}

printf("/n");

 

}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值