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

Re:帮忙看看啊,VC运行成功了,但就是WA啊!

Posted by S07zld at 2009-08-25 11:33:55 on Problem 1007
In Reply To:Re:帮忙看看啊,VC运行成功了,但就是WA啊! Posted by:zjazczjazc at 2009-07-23 10:39:18
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n,m,i,j;
	char a[100][51] = {0};
	int b[55] = {0};//记录每行的逆序数
	int count;

	int flag;
	int temp;
	char c[51] = {0};

	cin >> n >> m;

	//直接一一计算各个字符串的逆序数,每串中都依次向后比较各个字母
	for(i=0; i<m; i++)
	{
		cin >> a[i];//输入一个串

		count = 0;//临时变量用来计数

		//记录每串的逆序数,若不是由大到小排列则记录下其数目
		for(j=0; j<n; j++)
		{
			for(int k=j; k<n; k++)
			{
				if(a[i][k] < a[i][j])
					count ++; 			
			}
		}

		b[i] = count;
	}

	//数字有小到大排序,相应的字符串也相应改变次序(冒泡排序的变形)

	for(i=1; i < m; i++)
	{
		flag = 0; 

		for(j=m-1; j>=i; j--)
		{
			if(b[j] < b[j-1])
			{
				//数字交换
				temp = b[j-1];
				b[j-1] = b[j];
				b[j] = temp;

				//相应的字符串交换
				strcpy(c,a[j]); 
				strcpy(a[j],a[j-1]);
				strcpy(a[j-1],c);

				flag = 1;
			}
		}

		if(flag == 0)
			break;
	}
	
	//输出排序后的各个字符串
	for(i=0; i<m; i++)
	{
		cout << a[i] << 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