hdu 1251 统计难题
来源:互联网 发布:闲鱼如何申请淘宝介入 编辑:程序博客网 时间:2024/05/16 17:18
字典树的处!开始g++提交超内存,改c++提交就过了!
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<string>using namespace std;typedef struct T{ T* next[26]; int v;}T;T* root;int ct(string s){ int j; T *p=root,*q; for(int i=0;i<s.size();i++) { j=s[i]-'a'; if(p->next[j]==NULL) { q=(T*)malloc(sizeof(T)); q->v=1; for(int k=0;k<26;k++) q->next[k]=NULL; p->next[j]=q; p=p->next[j]; } else { p->next[j]->v++; p=p->next[j]; } } return 0;}int ft(string ss){ T *p=root; for(int i=0;i<ss.size();i++) { int j=ss[i]-'a'; p=p->next[j]; if(p==NULL) return 0; } return p->v;}int main(){ string str; root=(T*)malloc(sizeof(T)); for(int i=0;i<26;i++) root->next[i]=NULL; while(getline(cin,str),str!="") { ct(str); } while(cin>>str) { int ans=ft(str); printf("%d\n",ans); } return 0;}
0 0
- HDU 1251 统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- HDU 1251:统计难题
- HDU 1251 统计难题
- Hdu-1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- HDU-1251-统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- hdu 1251统计难题
- hdu 1251 统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- 初读《演说之禅设计篇》有感
- Android之点击回退键俩次退出程序
- Appium移动自动化测试(五)——获取apk的package、activity和element
- 编程珠玑——字符串移位
- C#解析Json数据(利用Newtonsoft.Json库)
- hdu 1251 统计难题
- android调用webservice带soapheader验证
- android开发环境
- Java finally语句到底是在return之前还是之后执行?
- 说说TDD的好处和坏处-对话
- JAVA自增陷阱
- ISO C++11 doesn't allow conversion from string literal to 'char*'
- 互联网语言与文化
- servlet/filter/listener/interceptor区别与联系