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 的code

Posted by H2O at 2006-04-16 14:24:50 on Problem 1007
In Reply To:我也贴一个又 WA 的code Posted by:xianyunsc at 2006-04-16 14:05:58
#include <stdio.h>
#include <string.h>

int m,n;  // m test line with the length of n;
int disorder(char *s)  
{
	int i,j,count = 0;
	for(i = 0; i < n-1; i++)
		for(j = i+1; j < n; j++)
		{
			if(s[j] < s[i] ) count ++;
		}
		return count;
}

int main()
{
	int order[60];
            ~~~~~~~~~~~~~~~60太小了,换order[105];

	char data[105][60];
	while(scanf("%d%d",&n,&m) == 2 )
	{
		int i,j;
		for(i = 0; i < m; i++)
		{
			scanf("%s",data[i]);
			order[i] = disorder(data[i]);
		}
		for(i = 0; i < m - 1; i++)   // sort	
		{
			bool changed = false;
			for(j = 0; j < m - i - 1; j++)
			{
				if(order[j+1] < order[j])
				{
					changed = true;
					char s[105];
					strcpy(s,data[j]);
					strcpy(data[j],data[j+1]);
					strcpy(data[j+1],s);
					int temp =order[j+1];
					order[j+1] = order[j];
					order[j] = temp;
				}
			}
			//if(!changed) break;
		}
		for(i = 0; i < m; i++)
			printf("%s\n",data[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