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:为什么一直WA。。。。

Posted by holmes93 at 2012-01-21 12:06:01 on Problem 1007
In Reply To:为什么一直WA。。。。 Posted by:holmes93 at 2012-01-21 11:08:59
自己解决了~一个是数组开反了==~另一个是不能用字符串最后一个存逆序数~否则超过255会出bug

附上代码~0ms~


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
  int len,n,i,j,k,count[100]={0},tem;
  char s[100][52];
  char *p[100],*temp;
  
  /*输入并计算逆序*/
  scanf ("%d%d",&len,&n);
  getchar();
  for (i=0;i<n;i++)           
  {
    gets(s[i]);
    p[i]=s[i];
    for (j=0;j<len-1;j++)
    {
        for (k=j+1;k<len;k++)
            if (s[i][j]>s[i][k])
                count[i]++; 
    }  
  }
  
  /*逆序数排序*/ 
  for (i=1;i<n;i++)
    for (j=0;j<n-i;j++)
    {
        if (count[j]>count[j+1])
        {
            tem=count[j];
            count[j]=count[j+1];
            count[j+1]=tem;
            temp=p[j];
            p[j]=p[j+1];
            p[j+1]=temp;    
        }    
    }
    
  /*输出*/
  for (i=0;i<n;i++)
    puts(p[i]);
  system("PAUSE");	
  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