样例输出:
Word #1: co-ch
coach
couch
Total number of candidate words = 2
Word #2: -at
cat
sat
Total number of candidate words = 2
Word #3: ---
cat
ali
sat
Total number of candidate words = 3
Word #4: ali
ali
Total number of candidate words = 1
Word #5: a-c
Total number of candidate words = 0
代码:
#include<iostream>
#include<string>
using namespace std;
string s[110],ss,t;
int n,m,k,cnt;
int main( )
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>s[i];
cin>>m;
for(int i=1;i<=m;i++)
{
cnt=0;
cin>>t;
int le=t.size();
printf("Word #%d: ",i);
cout<<t<<endl;
for(int j=1;j<=n;j++)
{
ss=s[j];
int len=ss.size();
if(le==len)
{
for(k=0;k<len; )
{
if(t[k]==ss[k]||t[k]=='-')
k++;
else break;
}
if(k==len)
{
cnt++;
cout<<ss<<endl;
}
}
else continue;
}
printf("Total number of candidate words = %d",cnt);
if(i!=m) cout<<endl<<endl;
}
return 0;
}