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 lambertwuyuil at 2011-08-04 13:59:27 on Problem 1007
#include "stdio.h"
//该函数用来每组数据中的逆序对个数
int cal_inversions(char* v[],int n)
{
	int i,j,k=0;
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(*v[i]>*v[j])
				k++;
	return(k);
}


void main()
{
	int m,n,i,j,k[100],t[50];
	char mn[100][50];
	scanf("%d%d",&m,&n);

	//用来求每个字符串所对应的逆序对个数,记入k[]中
	for(i=0;i<m;i++)
	{
		scanf("%s",mn+i);
		k[i]=cal_inversions(mn+i,n);
	}
	//对逆序对个数进行排序,并将对应下标绑定结果到t[],
	for(i=0;i<n;i++)
	{
		int temp=0;
		for(j=i+1;j<n;j++)
			if(k[i]>k[j])
			i=j,temp=i;
		t[i]=temp;
	}

	//打印结果,
	for(i=0;i<m;i++)
		printf("%s\n",mn[t[i]]);
}

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