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

总是Sample对,Result:Wrong Answer 。 谁能帮我看看呢。

Posted by Judas at 2005-08-02 10:43:10 on Problem 1007
Source

Problem Id:1007  User Id:Judas 
Memory:28K  Time:0MS
Language:C++  Result:Wrong Answer

Source 

#include<iostream.h>
#include<string.h>
#include <malloc.h>

int a[101];

void merge(int a[],int *temp,int l,int m,int r)
{
 int i,j,k;
 for(i=m+1;i>l;i--)temp[i-1]=a[i-1];
 for(j=m;j<r;j++)temp[r+m-j]=a[j+1];
 for(k=l;k<=r;k++)
 {
  if(temp[i]<temp[j])
   a[k]=temp[i++];
  else
   a[k]=temp[j--];
 }
}
void mergesort(int a[],int *temp,int l,int r)
{
 int m=(l+r)/2;
 if(r<=l)return;
 mergesort(a,temp,l,m);
 mergesort(a,temp,m+1,r);
 merge(a,temp,l,m,r);
}


void main()
{
	int n,m,i,j,k,flag[101],f=0,l,ff;
	char s[101][51];
	cin>>n>>m;
	memset(flag,m,sizeof(flag));
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)	cin>>s[i][j];
		s[i][50]=0;
		for(j=0;j<n-1;j++)	
			for(l=0;l<n-j;l++)
				if (s[i][j+l]<s[i][j]) s[i][50]++;
		a[i]=s[i][50];
		//cout<<a[i]<<endl;
	}
	
	int length=m;
	int *temp=(int*)malloc(sizeof(int)*length);
	mergesort(a,temp,0,length-1);

	cout<<endl;
	for(i=0;i<m;i++)
	{
		//cout<<a[i]<<endl;
		for(j=0;j<m;j++)
		{
			ff=0;
			if ( s[j][50]==a[i] ) 
			{
				for(l=0;l<f;l++)	if (j==flag[l])	ff=1;
				if (1!=ff) 
				{
					for(k=0;k<n;k++) cout<<s[j][k];	
					flag[f]=j;f++;
					cout<<endl;
					continue;
				}
			}
		}
	}

}


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