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

Runtime Error,可能是什么错误呢?

Posted by JLT at 2011-09-29 16:47:02 on Problem 1007
用的是qsort函数,上代码:
#include <stdio.h>
#include <stdlib.h>

int compare (void const * pFirst, void const *pSecond);

int iLength, iCount;

int main ()
{
	int iTmp, iTmp2, iTmp3;
	char (* strTable)[51];
#ifndef ONLINE_JUDGE
	freopen ("data.txt", "r", stdin);
#endif
	scanf ("%d%d\n", &iLength, &iCount);
	strTable = (char (*)[51])malloc (sizeof (char) * (51) * iCount / sizeof (size_t));
	for (iTmp = 0; iTmp < iCount; ++ iTmp)
	{
		gets (strTable[iTmp]); 
	}
	qsort (strTable, iCount, sizeof(char) * (51), compare);
	for (iTmp = 0; iTmp < iCount; ++ iTmp)
	{
		puts (strTable[iTmp]);
	}
	free (strTable);
	return 0;
}

int compare (void const * pFirst, void const *pSecond)
{
	return (getLength (pFirst) - getLength (pSecond));
}

int getLength (const char *strDNA)
{
	int iResult = 0;
	int iTmp2, iTmp3;
	for (iTmp2 = 0; iTmp2 < iLength; ++ iTmp2)
	{
		for (iTmp3 = iTmp2; iTmp3 < iLength; ++ iTmp3)
		{
			if (strDNA[iTmp3] < strDNA[iTmp2])
				++ iResult;
		}
	}
	return iResult;
}




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