| ||||||||||
| 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 | |||||||||
怎么会re呢? 大牛帮看下,谢谢!!In Reply To:怎么会re呢? Posted by:dong930 at 2007-08-10 17:18:00 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct word
{
char p[15],n[15];
struct word *nex;
}a[35],*head;
int cmp(const void *a,const void *b)
{
struct word x=*(struct word *)a,y=*(struct word *)b;
int z=strcmp(x.n,y.n);
if(z>0)return 1;
else return -1;
}
main()
{
int t,i;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
int n,j,k;
scanf("%d",&n);
head=NULL;
for(j=1;j<n;j++)
{scanf("%s%s",a[j].p,a[j].n);a[j].nex=NULL;}
qsort(a+1,n-1,sizeof(a[1]),cmp);
for(k=1;k<n;k++)
{
for(j=1;j<n;j++)
{
int from=1,to=n-1;
while(from<=to)
{
int middle=(from+to)/2,z=strcmp(a[j].n,a[k].p);
if(!z)
{
from=to;a[j].nex=&a[k];break;
}
else
{
if(z<0)from=middle+1;
else to=middle-1;
}
}
if(from>to)
head=&a[k];
}
}
printf("Scenario #%d:\n",i);
while((*head).nex)
{
printf("%s\n",(*head).p);
head=(*head).nex;
}
printf("%s\n",(*head).p);
printf("%s\n",(*head).n);
printf("\n");
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator