Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Runtime Error,可能是什么错误呢?用的是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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator