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

真怪了,我用Trie能过,但用快排就是过不了,谁能帮忙看看快排哪里有错啊?

Posted by alazyrabbit at 2009-08-31 17:19:41 on Problem 2001
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <string.h>
#define M 1100
using namespace std;
char c[M][30],d[M],l[M];
int n;
bool cmp(int x,int y){
	int i=0;
	while(c[x][i]==c[y][i]&&c[x][i]&&c[y][i])
		i++;
	return c[x][i]<c[y][i];
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,j2;
	n=0;
	while(scanf("%s",c[n])!=EOF){
		d[n]=n;
		n++;
	}
	sort(d,d+n,cmp);
	memset(l,0,sizeof(l));
	for(i=0;i<n-1;i++){
		int j=d[i];j2=d[i+1];
		k=0;
		while(c[j][k]==c[j2][k]&&c[j][k]&&c[j2][k])
			k++;
		if(k>l[j])l[j]=k;
		if(k>l[j2])l[j2]=k;
	}
	for(i=0;i<n;i++){
		if(c[i][0]){
			printf("%s ",c[i]);
			for(j=0;j<l[i];j++)
				printf("%c",c[i][j]);
			if(c[i][j]!=0)
				printf("%c",c[i][j]);
		}
		printf("\n");
	}
	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