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 |
一定要注意,声明字符数组时长度为51#include <iostream> using namespace std; int GetInverse(char *str) { int rst = 0; int l = (int)strlen(str); for (int i = 0; i < l; i++) for (int j = i + 1; j < l; j++) if (str[i] > str[j]) rst++; return rst; } int sort_function(const void *a, const void *b) { if (((int*)a)[1] < ((int*)b)[1]) return -1; else if (((int*)a)[1] > ((int*)b)[1]) return 1; else return 0; } int main() { int n, m, sort[100][2]; char src[100][51]; //这里一定要声明51,否则Output Limit Exceeded cin >> n >> m; for (int i = 0; i < m; i++) { cin >> src[i]; sort[i][0] = i; sort[i][1] = GetInverse(src[i]); } qsort((void*)sort, m, sizeof(sort[0]), sort_function); for (int i = 0; i < m; i++) cout << src[sort[i][0]] << endl; return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator