| ||||||||||
| 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 | |||||||||
求解啊,为啥子用C++编译就CE啊#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct arr{
int dat[26],next[26];
}t[20001];
char s[1001][21];
int n,tot;
void insert(char *s){
int now = 0,tem;
int len = strlen(s);
for (int i = 0; i < len; i++){
tem = s[i]-97;
t[now].dat[tem]++;
if (!t[now].next[tem]){
t[now].next[tem] = ++tot;
now = tot;
}
else{
now = t[now].next[tem];
}
}
}
string find(char *s){
string temp;
int tem,now = 0;
int len = strlen(s);
for (int i = 0; i < len; i++){
tem = s[i]-97;
temp += s[i];
if (t[now].dat[tem] == 1) return temp;
now = t[now].next[tem];
}
return temp;
}
int main(){
int i;
while (~scanf("%s",s[++n])){
insert(s[n]);
}
n--;
for (i = 1; i <= n; i++){
printf("%s ",s[i]);
cout<<find(s[i])<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator