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

怎么一直是WA?找不到原因

Posted by phantomr at 2005-04-24 18:35:07 on Problem 1007
#include <stdio.h>

int num(char a[],int n)
{int i,j,s=0;
 for(i=0;i<n-1;i++)
 for(j=i+1;j<n;j++)
 if(a[i]>a[j])
 s++;
 return s;}
        
void swap(char *a,char *b)
{char c;
 c=*a;
 *a=*b;
 *b=c;}    

main()
{
    char input[100][53];
    int i,j,m,n,t;
    
    scanf("%d %d",&n,&m);

    for(i=0;i<m;i++)
    {scanf("%s",input[i]);
     input[i][n+1]=num(input[i],n);
     input[i][n+2]=i;}
    
    for(j=0;j<m;j++)
    for(i=j+1;i<m;i++)
    if(input[j][n+1]>input[i][n+1])
   {swap(&input[j][n+1],&input[i][n+1]);
    swap(&input[j][n+2],&input[i][n+2]);}
    
    for(j=0;j<m;j++)
    for(i=j+1;input[j][n+1]==input[i][n+1];i++)
    if(input[j][n+2]>input[i][n+2])
    {swap(&input[j][n+1],&input[i][n+1]);
     swap(&input[j][n+2],&input[i][n+2]);}
    
    for(i=0;i<m;i++)
    printf("%s\n",input[input[i][n+2]]);
}    

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