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

求助,老是Wrong Answer

Posted by pkuusb at 2007-11-22 12:46:34 on Problem 1007
以下是小弟1007的代码,其中用到了STL qsort排序函数,其本思想是通过该函数实现字符串按inversion值从小到大排序,可怎么老出是Wrong Answer呢?

#include<iostream>
#include<algorithm>
using namespace std;
int inversion(const char* s)
{
	int n=strlen(s);
	int result=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(s[i]>s[j]) result++;
	return result;
}
int compare(const void* s1,const void* s2)
{
	if(inversion((char*)s1)>=inversion((char*)s2)) return true;
	else return false;
}

int main()
{
	char input[100][50];
	int n,m,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%s",input[i]);
	}
	qsort((void*)input,m,sizeof(input[0]),compare);
	for(i=0;i<m;i++)
		printf("%s\n",input[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