题意:给一些单词,然后一些询问,如果能找到原单词,输出correct,否则有下面三种情况:
1.长度相同. 2.带检测字长度比字典里的字少1 3.带检测字长度比字典里的字多1
检查是否只有一个字母不同,输出所以满足相似的单词。
#include<iostream> #include<algorithm> #include<queue> #include<vector> #include<string> #include<cstring> #include<cstdio> const int maxn=100005; const int INF=0x3f3f3f3f; typedef long long LL; using namespace std; string a[maxn]; int n=0; void find(string s) { //找原单词 for(int i=0;i<n;i++) { if(a[i]==s) { cout<<s<<" is correct"; return ; } } //检查长度相同或多1或少1的情况 cout<<s<<": "; for(int i=0;i<n;i++) { int len=a[i].length(); if(len==s.length()) { int t=0; for(int j=0;j<len;j++) { if(a[i][j]==s[j]) t++; } if(t==len-1) cout<<a[i]<<" "; } else if(len==s.length()-1) { int t=0,p=0; for(int j=0;j<s.length();j++) { if(s[j]==a[i][p]) { t++; p++; } } if(t==len) cout<<a[i]<<" "; } else if(len==s.length()+1) { int t=0,p=0; for(int j=0;j<len;j++) { if(a[i][j]==s[p]) { t++; p++; } } if(t==s.length()) cout<<a[i]<<" "; } } } int main() { // freopen("E:\\ACM\\test.txt","r",stdin); string s; while(cin>>s,s!="#") { a[n++]=s; } while(cin>>s,s!="#") { find(s); puts(""); } return 0; }