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

求解啊,为啥子用C++编译就CE啊

Posted by Gazer_Fri at 2014-04-16 14:58:04 on Problem 2001
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator