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

晒代码 终于AC了 一直都是数组小了

Posted by wind_snghaY at 2010-08-23 17:45:21 on Problem 1007
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX   101
#define CASES 50
int compare(const void * a,const void * b)
{
	return (*(int *)a-*(int *)b);
}
void main()
{
	int  compare(const void * a,const void * b);
	char string[MAX][CASES]={0};
	int  num[MAX]={0};
	int  cases,len;
	int  i,j;
	int  con,a[4];
	scanf("%d%d",&len,&cases);
	for(i=0;i<cases;i++)
	{
		scanf("%s",string[i]);
		for(j=strlen(string[i])-1,con=a[0]=a[1]=a[2]=a[3]=0;j>=0;j--)
			switch(string[i][j])
		{
			case 'A':	a[1]++;
						a[2]++;
						a[3]++;
						break;
			case 'C':	a[2]++;
						a[3]++;
						con=con+a[1];
						break;
			case 'G':	a[3]++;
						con=con+a[2];
						break;
			case 'T':	con=con+a[3];
						break;
		}
		num[i]=con*1000+i;
	}
	qsort(num,cases,sizeof(num[0]),compare);
	for(i=0;i<cases;i++)
		printf("%s\n",string[num[i]%1000]);
}

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