| ||||||||||
| 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 | |||||||||
真怪了,我用Trie能过,但用快排就是过不了,谁能帮忙看看快排哪里有错啊?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator