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

谁帮我看看这个程序有什么问题?

Posted by feisky at 2009-11-30 21:42:24 on Problem 1007
#include <stdio.h>
#include <string.h>

int main()
{
	int length,num;
	char str[50][100];
	char strtemp[100];
	int i,j,m,temp=0,n=0;
	int sort[50];
	scanf("%d %d",&length,&num);

	for(n=0;n<num;n++)
	{
		scanf("%s",str[n]);
		for(i=0;i<length-1;i++)
		{
			for(j=i+1;j<length;j++)
			{
				if(str[n][i]>str[n][j])
				   temp+=str[n][i]-str[n][j];
			}
		}
		sort[n]=temp;
		temp=0;
	}

	for(i = 0; i < num-1; i++)
	{
		m = i;
		for(j = i+1; j < num; j++)
			if(sort[j] < sort[m])
				m = j;

		if(i != m)
		{
			temp=sort[i];
			sort[i]=sort[m];
			sort[m]=temp;

			strcpy(strtemp,str[i]);
			strcpy(str[i],str[m]);
			strcpy(str[m],strtemp);

		}
	}

	for(i = 0; i < num-1; i++)
	{
		if(str[i]>str[i+1])
		{
			strcpy(strtemp,str[i]);
			strcpy(str[i],str[i+1]);
			strcpy(str[i+1],strtemp);
		}
	}

	for(i = 0; i < num; i++)
	{
		printf("%s\n",str[i]);
	}
	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