sdutacm-迷之好奇
来源:互联网 发布:下载通达信炒股软件 编辑:程序博客网 时间:2024/04/29 21:22
迷之好奇
TimeLimit: 2000MS Memory Limit: 65536KB
SubmitStatistic
Problem Description
FF得到了一个有n个数字的集合。不要问我为什么,有钱,任性。
FF很好奇的想知道,对于数字x,集合中有多少个数字可以在x前面添加任意数字得到。
如,x = 123,则在x前面添加数字可以得到4123,5123等。
Input
多组输入。
对于每组数据
首先输入n(1<= n <= 100000)。
接下来n行。每行一个数字y(1 <= y<= 100000)代表集合中的元素。
接下来一行输入m(1 <= m <= 100000),代表有m次询问。
接下来的m行。
每行一个正整数x(1 <= x <= 100000)。
Output
对于每组数据,输出一个数字代表答案。
Example Input
3
12345
66666
12356
3
45
12345
356
Example Output
1
0
1
Hint
Author
zmx
#include <stdio.h> #include <string.h> int top; struct node { int next[26]; int flag; } st[5001000]; int creat() { memset(st[top].next,-1,sizeof(st[top].next)); st[top].flag=0; return top++; } void insertt(int root,char*s) { int len=strlen(s); for(int i=len-1; i>=0; i--) { int t=s[i]-'0'; if(st[root].next[t]==-1) { st[root].next[t]=creat(); } st[root].flag++; root=st[root].next[t]; } } int cmp(char *s,int root) { int len=strlen(s); for(int i=len-1; i>=0; i--) { int t=s[i]-'0'; if(st[root].next[t]==-1) { return 0; } root=st[root].next[t]; } return st[root].flag; } int main() { int n,m,root; char s[101]; char s1[101]; while(~scanf("%d",&n)) { top=0; root=creat(); while(n--) { scanf("%s",s); insertt(root,s); } scanf("%d",&m); while(m--) { scanf("%s",s1); printf("%d\n",cmp(s1,root)); } } return 0; } /***************************************************User name: jk160505徐红博Result: AcceptedTake time: 388msTake Memory: 1396KBSubmit time: 2017-02-10 16:44:15****************************************************/
0 0
- sdutacm-迷之好奇
- SDUT 迷之好奇
- 迷之好奇
- 迷之好奇
- 迷之好奇
- 迷之好奇
- 迷之好奇 SDUTOJ 3039
- SDUT 3039 迷之好奇(哈希)
- 迷之好奇 —静态字典树
- SDUT_3039 迷之好奇 【字典树】
- SDUTOJ 3039 迷之好奇 静态字典树
- 好奇!
- 好奇
- SDUTACM 数据结构实验之查找一:二叉排序树
- SDUTACM 数据结构实验之图论四:迷宫探索
- SDUTACM 数据结构实验之链表八:Farey序列
- sdutacm-数据结构实验之排序三:bucketsort
- sdutacm-数据结构实验之链表八:Farey序列
- 使用largeHeap为app增加可使用内存
- Java中的泛型概念学习
- Android Eclipse 里面依赖工程无法关联源码解决方案
- 通过C语言娶百富美之链表与结构体结合!!!!!!
- 查验身份证
- sdutacm-迷之好奇
- NYOJ 417 死神来了 鸽巢原理
- Median of Two Sorted Arrays(求两个数组的中位数)
- sdutacm-数组计算机
- Python中子类如何获取父类的类成员
- 正确率、召回率、F1-Score
- Two Sum
- SQLite的一些须知和容易遗忘的知识点
- sdutacm-效率至上