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 CCUT2015_wangzhao at 2014-10-20 20:07:29 on Problem 1007
为什么对数组排序就可以了 不是比的逆序数的大小么?我第一用c++写的,为什么WA
#include<fstream>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	fstream cin("test.txt");
	int n,m,s[51];
	char a[200][100];
	memset(s,0,sizeof(s));
	memset(a,0,sizeof(a));
	int i,j,k;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			for(k=j;k<n;k++)
				if(a[i][j]>a[i][k])
					s[i]++;
		}
	}
	int min,temp=m;
	while(temp)
	{
		min=0;
		if(s[min]<0)
			while(s[min]<0)
				min++;
		for(i=0;i<m;i++)
			if(s[min]>s[i]&&s[i]>=0)
				min=i;
		s[min]=-1;
		cout<<a[min]<<endl;
		temp--;
	}
	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