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 |
悲剧了,就是过不了,连网上找的AC的代码直接粘贴上也WA了,难道真的是人品问题...如题,自己的代码: #include <iostream> #include <cstring> using namespace std; struct Node { int count; char string[55]; void Calculate() { count = 0; for (int i = 0; string[i]; i++) for (int j = i+1; string[j]; j++) if (string[j] < string[i]) count++; } }nd[105], t; void swap(Node& a, Node& b) { t = a; a = b; b = t; } void sort(int m) { int i, j, k; for (i = 0; i < m; i++) { k = i; for (j = i+1; j < m; j++) { if (nd[j].count < nd[k].count) k = j; else if (nd[j].count == nd[k].count) { if (strcmp(nd[j].string, nd[k].string) < 0) k = j; } } if (k != i) swap(nd[k], nd[i]); } } int main() { int i, m, n; while (scanf("%d%d", &n, &m) == 2) { for (i = 0; i < m; i++) { scanf("%s", &nd[i].string); nd[i].Calculate(); } sort(m); for (i = 0; i < m; i++) puts(nd[i].string); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator