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 wangjifeng1 at 2011-06-10 20:31:26 on Problem 1007
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct DNA{
	char str[51];
	int sort;
	}d[101];
	
int cmp(const void *a,const void *b)
{
	if( ((DNA*)a)->sort != ((DNA*)b)->sort  ) 
	return ((DNA*)a)->sort > ((DNA*)b)->sort;//sort從小到大 
	 
	return 1;//
	 //return strcmp( ((DNA*)a)->str,((DNA*)b)->str  );//字典升序 
	}	

int main()
{
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	int n,m,i,j,k;
	
	scanf("%d%d",&n,&m);
	getchar();
	
	for(i=0;i<m;i++)
	  gets(d[i].str);
	  
	for(i=0;i<m;i++)
	{
		d[i].sort=0; 
	  for(j=0;j<n;j++)
	     for(k=j+1;k<n;k++)
	     if(d[i].str[j]>d[i].str[k]) d[i].sort++;
    }
    
    qsort(d,m,sizeof(d[0]),cmp);
    
    for(i=0;i<m;i++)
    printf("%s\n",d[i].str,d[i].sort);
    
	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