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

Re:好心人,帮我看一下吧。谢谢!

Posted by yujiashan at 2006-12-09 22:22:31 on Problem 2001
In Reply To:好心人,帮我看一下吧。谢谢! Posted by:yujiashan at 2006-12-09 22:09:36
> 不知道错哪里了。
>                郁闷,在线等...
> 
> #include<iostream.h>
> #include<stdlib.h>
> #include<string.h>
> struct prefix
> {
>        int k;
>        char str1[22],str2[22];
> }mmd[1000];
> int cmp1(const void *a,const void *b)
> {
>     return strcmp(((prefix*)a)->str1,((prefix*)b)->str2);
> }
> int cmp2(const void *a,const void *b)
> {
>     return ((prefix*)a)->k-((prefix*)b)->k;
> }
> int main()
> {
>     int i=0,m1=0,m2=0,j,len,min;
>     while (cin>>mmd[i].str1)
>     {
>           mmd[i].k=i;
>           i++;
>     }
>     len=i;
>     qsort(mmd,len,sizeof(mmd[0]),cmp1);
>     for (i=0;i<len;i++)
>     {
>         if (i!=len-1)
>         {
>            for (j=0;mmd[i].str1[j]!='\0'&&mmd[i+1].str1[j]!='\0';j++)
>                if (mmd[i].str1[j]!=mmd[i+1].str1[j])
>                   break;
>            m2=j;
>         }
>         else
>              m2=0;
>         min=(m1>m2)?m1:m2;
>         for (j=0;j<=min;j++)
>             mmd[i].str2[j]=mmd[i].str1[j];
>         mmd[i].str2[min+1]='\0';
>         m1=m2;
>     }
>     qsort(mmd,len,sizeof(mmd[0]),cmp2);
>     for (i=0;i<len;i++)
>         cout<<mmd[i].str1<<" "<<mmd[i].str2<<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