Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 真是见鬼了，把char 数组放在全局开个1001过了，放在局部得开10001个。活见鬼，这题真是奇葩了。

Posted by zmx1 at 2016-08-10 23:42:06 on Problem 2001
```#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 2000 * 20 + 1;

const int sig_size = 26;

struct trie{

int ch[maxn][sig_size];
int hz[maxn][sig_size];

int val[maxn];

int sz;

void init(){

sz = 1;
memset(hz, 0, sizeof(hz));
memset(ch, 0, sizeof(ch));
memset(val, 0, sizeof(val));
}

void insert(  char s[][22] , int start, int v){

int u = 0;

int len = strlen(s[start]);

for (int i = 0; i<len; i++){

int c = s[start][i] - 'a';

if (!ch[u][c]){

memset(ch[sz], 0, sizeof(ch[sz]));

val[sz] = 0;

ch[u][c] = sz++;

}

hz[u][c]++;

u = ch[u][c];

}

val[u] = v;

}

int  query(char s[][22], int start){

int u = 0;

int len = strlen(s[start]);

for (int i = 0; i < len; i++){

int c = s[start][i] - 'a';

if ( hz[u][c] == 1 )return i;

//if(i==len-1)return i;

u = ch[u][c];

}

return len-1;//我本来写的是if(i==len-1) return i，这句本来是没有的总是WA，就把上面这句注释掉，写了这句。但我感觉应该一样啊，除非有len=0，没进循环，应该不会呀。见鬼了。见鬼了。
}

}    node;

int main(){

char input[10001][22];

node.init();

int cas = 0;

while ( scanf("%s", input[cas]) != EOF){

node.insert(input, cas , 1);

++cas;
}

for(int i=0;i<=cas;i++){

cout<<input[i]<<" ";

for(int j=0;j<=node.query(input,i);j++){

printf("%c",input[i][j]);
}
printf("\n");
}

return 0;
}
```

Followed by: