hdu 1800 Flying to the Mars
http://acm.hdu.edu.cn/showproblem.php?pid=1800
这个题,就是在插入的时候注意一下前导零的问题,其他的就没什么了,祝君ac。
上代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; const int maxn=10; struct node { int cnt; node *next[maxn]; node() { cnt=0; for(int i=0;i<maxn;i++) next[i]=NULL; } ~node() { for(int i=0;i<maxn;i++) { if(next[i]!=NULL) next[i]=NULL; } } }; inline int max(int a,int b) { return a<b?b:a; } int n,ans; class Trie { public: node *root; Trie() { root=NULL; } void insert(char *s) { if(!root) root=new node(); int len=strlen(s); node *loca=root; for(int i=0;i<len;i++) { int id=s[i]-'0'; if(loca->next[id]==NULL) loca->next[id]=new node(); loca=loca->next[id]; } loca->cnt++; ans=max(loca->cnt,ans); // printf("%s: %d\n",s,ans); } }; int main() { char s[31]; while(~scanf("%d",&n)) { Trie t; ans=0; for(int i=0;i<n;i++) { scanf("%s",s); int index=0; while(s[index]=='0') index++; // cout<<s+index<<endl; t.insert(s+index); } printf("%d\n",ans); } return 0; }
善待每一天,努力做好自己。
欢迎转载,注明出处。
勸君惜取少年時&莫待無花空折枝
posted on 2013-05-09 13:04 Raining Days 阅读(140) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步