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

[求教]在VC6.0可以通过,但一提交就Wrong Answer.

Posted by dgcjoy at 2007-05-02 22:03:02 on Problem 1007
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int m,n,i,j,k,l;
	int *count,*flag;
	char *p[100];
	char temp;
	scanf("%d%d",&n,&m);

	count = (int *)malloc(m*sizeof(int));
	flag = (int *)malloc(m*sizeof(int));
	for(i=0; i<m; i++)
		p[i] = (char *)malloc(n*sizeof(char));
	for(i=0; i<m; i++)
	{
		count[i] = 0;
		flag[i] = 1;
	}

	for(i=0; i<m; i++)
		scanf("%s",p[i]);

	for(i=0; i<m; i++)
		for(j=0; j<n-1; j++)
		{
			temp = p[i][j];
			for(k=j+1; k<n; k++)
			{
				if(temp>p[i][k])
					count[i]++;
			}
		}
	for(i=0,k=-1,l=m; i<m && l>0; i++,l--)
	{
		if( k!=i-1 )
			i--;
		k = i;
		for(j=i+1; j<m; j++)
			if(count[j] < count[k] && flag[j])
				k = j;
		printf("%s\n",p[k]);
		flag[k] = 0;
	}
	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