Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
能想到的数据都试了一遍,都没错啊,提交就是WA。。找错都找了好几个小时了。。#include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> using namespace std; int tree[100005][10]; bool is[100005]; int tot; bool flag; void Insert(int rt,char *st) { int i=0; while(st[i]&&flag) { int v=st[i++]-'0'; if(tree[rt][v]==0) { tree[rt][v]=++tot; } else { if(is[rt]) flag=false; } rt=tree[rt][v]; } is[rt-1]=true; for(int k=0;k<10;k++) if(tree[rt][k]!=0) flag=false; } int main() { int t,n; char st[15]; cin>>t; while(t--) { tot=1; int rt=1; flag=true; scanf("%d",&n); memset(is,false,sizeof(is)); memset(tree[0],0,sizeof(tree[0])); for(int i=0;i<n;i++) { scanf("%s",st); if(flag) Insert(rt,st); } if(flag) printf("YES\n"); else printf("NO\n"); } return 0; } 找不出来不甘心啊。。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator