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,(C++),thx~

Posted by gxiverson at 2007-01-31 19:29:16 on Problem 1007
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int f(char a[51],int len)
{
	int sum=0;
	for(int i=1;i<=len-1;i++)
	{
		for(int j=i+1;j<=len;j++)
		{
			if(a[i]>a[j])
				sum++;
		}
	}
	return sum;
}
int main()
{
	int num,len,m,i,j;
	char a[101][51];
	cin>>len>>num;
	for(i=1;i<=num;i++)
	{
		for(j=1;j<=len;j++)
		{
			cin>>a[i][j];
		}
	}
	int p;
	p=f(a[1],len);
	for(i=1;i<=num;i++)
	{
		if(p<=f(a[i],len))
			p=f(a[i],len);
	}
    for(m=1;m<=p;m++)
	{
		for(i=1;i<=num;i++)
		{
			if(f(a[i],len)==m)
			{
				for(j=1;j<=len;j++)
				{
					cout<<a[i][j];
				}
				cout<<endl;
			}
		}
	}
	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