标签:
Northeastern Europe 1998
<span style="color:#000099;">/******************************************
author : Grant Yuan
time : 2014/10/3 0:38
algorithm : 暴力
source : POJ 1035
*******************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
const int MAX=10007;
struct word
{
char str[15];
int len;
};
word s[MAX];
int n;
queue<int> ans;
inline bool slove1(word s1,word s2)//推断两个字符串是否相等
{
if(strcmp(s1.str,s2.str)==0) return 1;
return 0;
}
inline bool slove2(word s1,word s2)//推断能否够由一个字符串添加或者降低一个字符得到还有一个字符串
{
int l1=s1.len,l2=s2.len;
int i,j;
bool ans=1;
for(i=0;i<l1&&i<l2;i++)
{
if(s1.str[i]!=s2.str[i]) ans=0;
}
if(ans) return 1;
for(i=0,j=0;i<l1&&j<l2;)
{
if(s1.str[i]==s2.str[j]){ i++;j++;}
else i++;
}
if(i==l1&&j==l2) return 1;
return 0;
}
inline bool slove3(word s1,word s2)//是否两个字符串仅仅有一个字符不想等
{
int ans=0;
int l=s1.len;
for(int i=0;i<l;i++)
{
if(s1.str[i]!=s2.str[i]) ans++;
}
if(ans==1) return 1;
return 0;
}
int main()
{
while(!ans.empty()) ans.pop();
word s1;
int n=0;
while(scanf(" %s",s1.str)!=EOF){
if(strcmp(s1.str,"#")==0) break;
strcpy(s[++n].str,s1.str);
s[n].len=strlen(s1.str);
}
while(scanf(" %s",s1.str)!=EOF){
while(!ans.empty()) ans.pop();
if(strcmp(s1.str,"#")==0) break;
bool flag=1;
s1.len=strlen(s1.str);
for(int i=1;i<=n;i++)
{
int l2=s[i].len,l1=s1.len;
bool ans1=0;
if(l1==l2){
if(slove1(s1,s[i])) ans1=1;
}
if(ans1){flag=0;printf("%s is correct\n",s1.str);break;}
if(l1==l2){
if(slove3(s1,s[i])) ans.push(i);
}
if(l1-l2==1){
if(slove2(s1,s[i])) ans.push(i);
}
if(l2-l1==1){
if(slove2(s[i],s1)) ans.push(i);
}
}
if(flag){
printf("%s:",s1.str);
while(!ans.empty()){printf(" %s",s[ans.front()].str);ans.pop();}
printf("\n");
}
}
return 0;
}
</span>
版权声明:本文博主原创文章,博客,未经同意,不得转载。
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/4759605.html