标签:esc desc queue typedef mat mes scan tput ane
题目链接:https://vjudge.net/problem/HDU-1251
banana band bee absolute acm ba b band abcSample Output
2 3 1 0
思路:字典树模板
// // Created by HJYL on 2019/8/17. // #include <iostream> #include <vector> #include <map> #include <string> #include <queue> #include <stack> #include <set> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> using namespace std; typedef long long ll; const int maxn=1e6+10; char str[maxn]; struct trie{ trie* next[26]; int sum; trie(){ for(int i=0;i<26;i++) { next[i]=NULL; } sum=0; } }root; void insert(char* s) { trie* p=&root; for(int i=0;s[i];i++) { if(p->next[s[i]-‘a‘]==NULL) { p->next[s[i]-‘a‘]=new trie; } p=p->next[s[i]-‘a‘]; p->sum++; } } int find(char* s) { trie* p=&root; for(int i=0;s[i];i++) { if(p->next[s[i]-‘a‘]==NULL) return 0; else p=p->next[s[i]-‘a‘]; } return p->sum; } int main() { //freopen("C:\\Users\\asus567767\\CLionProjects\\untitled\\text","r",stdin); while(gets(str)&&str[0]!=‘\0‘) { insert(str); } while(scanf("%s",str)==1) { printf("%d\n",find(str)); } return 0; }
标签:esc desc queue typedef mat mes scan tput ane
原文地址:https://www.cnblogs.com/Vampire6/p/11370882.html