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 给看看为什么WA

Posted by hch545767949 at 2013-01-29 00:34:43 on Problem 1007
#include<stdio.h>
#include<string.h>
int main()
{
    char str[102][55],temp[55];
    int m,n,q[102],min,s,i,k,a,b,c,d,e;

    scanf("%d%d",&n,&m);


            for(i=0;i<=m-1;i++)
                scanf("%s",str[i]);
            for(k=0;k<=m-1;k++)
                {
                    q[k]=0;
                    for(a=0;a<=n-2;a++)
                        for(b=a+1;b<=n-1;b++)
                            if(str[k][a]>str[k][b])
                                q[k]++;
                }
            for(c=0;c<=n-1;c++)
                for(d=0;d<=m-2;d++)
                    if(q[d]>q[d+1])
                        {
                            strcpy(temp,str[d]);
                            strcpy(str[d],str[d+1]);
                            strcpy(str[d+1],temp);
                            s=q[d];
                            q[d]=q[d+1];
                            q[d+1]=s;
                        }
            for(e=0;e<=m-1;e++)
            {
                printf("%s\n",str[e]);
            }


    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