| ||||||||||
| 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 | |||||||||
我会说我大小写错了吗贴一下代码吧
//poj3630 trie
//Can't judge if two strings are equal
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <cassert>
using namespace std;
const int MAXN = 10000 + 2, MAXL = 10 + 2;
struct Node{
int finish;
Node* son[10];
Node() { }
};
Node node[MAXN * MAXL];
Node *Root;
int Total = 0;
void insert(char *c, Node *v)
{
//cerr<<c<<endl;
int p = (*c) - '0';
if (*c == 0){
++(v->finish);
return;
}
assert( p >= 0 );
assert( p < 10 );
assert( *c != 0 );
if ( v->son[p] == NULL )
v->son[p] = &node[++Total];
insert(c+1, v->son[p] );
}
bool have_prefix(Node *v)
{
bool found = false;
if ( v->finish != 0 ){
for (int i = 0; !found && i < 10; ++i)
found = (v->son[i] != NULL);
}
else{
for (int i = 0; !found && i < 10; ++i)
if (v->son[i] != NULL)
found = have_prefix(v->son[i]);
}
return found;
}
int main()
{
char ori[MAXL];
int testcase, n;
scanf("%d", &testcase);
while (testcase--){
memset(node, 0, sizeof(node) );
Root = node;
Total = 0;
scanf("%d", &n);
while (n--){
scanf("%s", ori);
insert(ori, Root);
}
if ( !have_prefix(Root) )
printf("YES\n");
else
printf("NO\n");
}//while testcase--
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator