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

求解,为什么是WA?

Posted by dayou at 2011-12-03 21:26:42 on Problem 1007
#include <iostream>
#include <cstdlib>
using namespace std;

char str[100][50];
int num[100];//每一行的逆序对数
int flag[100];
int ssort[100];

int main()
{
	int n,m;
	cin>>n>>m;
	if(n<=0||n>50||m<=0||m>100) return 0;
	int a=0,b=0;//计数器
	int lcount;
	for(a=0;a<m;a++)
	{
		num[a]=0;
		flag[a]=0;
		ssort[a]=0;
		int count=0;
		for(count=0;count<n;count++)
		{
			cin>>str[a][count];
		}//得到一行字符串
		for(count=0;count<n;count++)
		{
			for(lcount=count;lcount<n;lcount++)
			{
				if(str[a][count]>str[a][lcount]) num[a]++;
			}
		}//得到逆序对数
	}
	for(a=0;a<m;a++)
	{
		for(lcount=0;lcount<m;lcount++)
		{
			if(num[a]>=num[lcount]) flag[a]++;
		}
		flag[a]=flag[a]*1000+a;
	}//得到flag值
	for(a=0;a<m;a++)
	{
		for(lcount=0;lcount<m;lcount++)
		{
			if(flag[a]<=flag[lcount]) ssort[a]++;
		}
	}//处理flag值并转为ssort值
	for(a=m;a>1;a--)
	{
		for(b=0;b<n;b++)
		{
			if(ssort[b]==a)
			{
				int p;
				for(p=0;p<n;p++)
				{
					cout<<str[b][p];
				}
			}
		}
		cout<<endl;
	}
	for(b=0;b<n;b++)
	{
		if(ssort[b]==1)
		{
			int q;
			for(q=0;q<n;q++)
			{
				cout<<str[b][q];
			}
		}
	}
	system ("pause");
	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