poj1035

来源:互联网 发布:脱口秀大会 知乎 编辑:程序博客网 时间:2024/05/21 11:27
#include<iostream>
#include<string>
using namespace std;
string dic[10000];
int diclength = 0;
string word;
string che[50];
int chelength = 0;


string matched[50] = {""};


void check();
int main()
{
while(cin>>word&&word!="#")


dic[diclength++] = word;
while (cin >> word&&word != "#")
che[chelength++] = word;
check();
for(int i=0;i<chelength;i++)
{
if (matched[i] == "#")
cout << che[i] << " is correct" << endl;
else
cout << che[i] << ":" << matched[i]<<endl;
}
return 0;
}


void check()
{
for(int i=0;i<chelength;i++)
{
word = che[i];
for(int j=0;j<diclength;j++)
{
int cha = 0;
cha = word.length() - dic[j].length();
int error = 0;
if(cha==0)
{
for(int t=0;t<word.length();t++)
{
if(word[t]!=dic[j][t])
{
error++;
if (error > 1)
break;
}
}
if (error == 1)
{
matched[i] += " ";
matched[i] += dic[j];
}
else if(error==0)
{
matched[i] = "#";
break;
}
}
if(cha==1)
{
for(int t=0,p=0;t<word.length();t++,p++)
{
if(word[t]!=dic[j][p])
{
error++;
if (error > 1)
break;
p--;
}
}
if (error == 1)
{
matched[i] += " ";
matched[i] += dic[j];
}
}
if (cha == -1)
{
for (int t = 0, p = 0; t<dic[j].length(); t++, p++)
{
if (word[p] != dic[j][t])
{
error++;
if (error > 1)
break;
p--;
}
}
if (error == 1)
{
matched[i] += " ";
matched[i] += dic[j];
}
}
}
}
}