记录编号 |
397917 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[Youdao2010] 有道搜索框 |
最终得分 |
100 |
用户昵称 |
devil |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.092 s |
提交时间 |
2017-04-21 10:49:39 |
内存使用 |
0.32 MiB |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <vector>
- #include <ctime>
- #include <map>
- #include <stack>
- #include <queue>
- #include <cstring>
- #include <algorithm>
- using namespace std;
-
- #define sacnf scanf
- #define scnaf scanf
- #define scanfi(x) scanf("%d",&x)
- #define scanfd(x) scanf("%lf",&x)
- #define scanfl(x) scanf("%lld",&x)
- #define scanfc(x) scanf("%c",&x)
- #define scanfs(x) scanf("%s",x)
- #define maxn 55
- #define maxm 26
- #define inf 1061109567
- #define Eps 0.00001
- const double PI=acos(-1.0);
- #define mod 1000000007
- #define MAXNUM 10000
- void Swap(int &a,int &b) {int t=a;a=b;b=t;}
- int Abs(int x) {return (x<0)?-x:x;}
- typedef long long ll;
- typedef unsigned int uint;
-
- struct node
- {
- bool End;
- node* next[maxm];
- } *root;
-
- char s[maxn],temp[maxn];
-
- node* create()
- {
- node *temp=(node*)malloc(sizeof(node));
- temp->End=false;for(int i=0;i<maxm;i++) temp->next[i]=NULL;
- return temp;
- }
-
- void Insert(node *root,char *s)
- {
- while(*s!='\0')
- {
- int t=*s-'a';
- if(root->next[t]==NULL)
- root->next[t]=create();
- root=root->next[t];s++;
- }
- root->End=true;
- }
-
- void Search(node *root,int len,int &cnt)
- {
- if(cnt>=8) return;
- if(root->End)
- {
- if(cnt!=0) printf(" ");
- printf("%s",temp);cnt++;
- }
- for(int i=0;i<26;i++)
- if(cnt<8&&root->next[i]!=NULL)
- {
- temp[len+1]='\0';temp[len]='a'+i;
- Search(root->next[i],len+1,cnt);
- temp[len]='\0';
- }
- }
-
- bool found(node *root,char *s)
- {
- int len=strlen(s);
- for(int i=0;i<len;i++) temp[i]=s[i];temp[len]='\0';
- while(*s!='\0')
- {
- int t=*s-'a';
- if(root->next[t]==NULL) return false;
- root=root->next[t];s++;
- }
- int cnt=0;
- if(root->End) {printf("%s",temp);cnt=1;}
- for(int i=0;i<26;i++)
- if(cnt<8&&root->next[i]!=NULL)
- {
- temp[len+1]='\0';temp[len]='a'+i;
- Search(root->next[i],len+1,cnt);
- temp[len]='\0';
- }
- return true;
- }
-
- int main()
- {
- freopen("youdao.in","r",stdin);
- freopen("youdao.out","w",stdout);
- //clock_t st=clock();
- int n;scanf("%d",&n);
- root=create();
- for(int i=1;i<=n;i++)
- {
- scanf("%s",s);
- Insert(root,s);
- }
- int q;scanfi(q);
- while(q--)
- {
- scanf("%s",s);
- if(found(root,s)) printf("\n");
- else printf("%s\n",s);
- }
- //clock_t ed=clock();
- //printf("\n\nTime Used : %.5lf Ms.\n",(double)(ed-st)/CLOCKS_PER_SEC);
- return 0;
- }