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:牛人们帮帮看看,我测试几组数据都没有问题,提交总说答案错误,第一次来,对与测试系统不太清楚

Posted by hubenlong at 2010-05-17 10:45:29 on Problem 1007
In Reply To:牛人们帮帮看看,我测试几组数据都没有问题,提交总说答案错误,第一次来,对与测试系统不太清楚 Posted by:hubenlong at 2010-05-15 15:45:58
> #include <stdio.h>
> #include <stdlib.h>
> 
> typedef struct inode{
> 	int UnsortNum;
> 	char *ptr;
> 	inode *next;
> }Inode,*pInode;
> 
> int CountUnsortNum(char buffer[],int m)
> {
> 	int i=0,j=0;
> 	int sum=0;
> 	for(i=0;i<m-1;i++)
> 		for(j=i+1;j<m;j++)
> 			if(buffer[i]>buffer[j])
> 				++sum;
> 	return sum;
> }
> 
> 
> int main()
> {
> 	int m,n,i,j;
> 	pInode plink;
> 	//char c;
> 	char **buffer;
> 	scanf("%d %d",&m,&n);
> 	buffer=(char**)malloc(n*sizeof(char*));
> 	for(i=0;i<n;i++)
> 		buffer[i]=(char*)malloc((m+1)*sizeof(char));
> 
> 	if(!buffer)
> 		exit(-1);
> 	char c;
> 	
> 	fflush(stdin);
> 	for(i=0;i<n;i++){
> 		for(j=0;j<m;j++){
> 			c=getchar();
> 			//printf("%c\n",c);
> 			while(c=='\n'||c=='\r'||c=='\t'||c==' ')
> 			{
> 				if(j!=0)
> 				{	
> 					printf("i is %d,j is %d\n",i,j);
> 					exit(-1);
> 				}
> 				c=getchar();
> 			}
> 		//	if((c!='A')&&(c!='T')&&(c!='G')&&(c!='C'))
> 		//		exit(-1);
> 			buffer[i][j]=c;
> 		}
> 		buffer[i][m]='\0';
> 	}
> 		
> 	plink=(pInode)malloc(sizeof(Inode));
> 	pInode p,ptemp;
> 	p=plink;
> 	p->next=NULL;
> 	
> 	for(i=0;i<n;i++){
> 		if(!(ptemp=(pInode)malloc(sizeof(Inode))))
> 			exit(-1);
> 		ptemp->ptr=buffer[i];
> 		ptemp->UnsortNum=CountUnsortNum(buffer[i],m);
> 		
> 		ptemp->next=NULL;
> 		p->next=ptemp;
> 		p=p->next;
> 	}
> 	int min=0;
> 	pInode premin;
> 
> 	while(plink->next){
> 		premin=plink;
> 		min=plink->next->UnsortNum;
> 		for(p=plink;p->next!=NULL;p=p->next)
> 		{
> 			if(p->next->UnsortNum<min){
> 				premin=p;
> 				min=p->next->UnsortNum;
> 			}
> 		}
> 		printf("%s\n",premin->next->ptr);
> 		p=premin->next;
> 		premin->next=p->next;
> 		free(p);
> 		p=NULL;
> 	}
> 	free(plink);
> 	plink=NULL;
> 	for(i=0;i<n;i++){
> 		free(buffer[i]);
> 		buffer[i]=NULL;
> 	}
> 	free(buffer);
> 	buffer=NULL;
> 
> 	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