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 |
个人觉得sample对但WA的童鞋最大可能排序算法有问题,我的菜菜代码最终用qsor排结构体t过的,代码如下供参考Source Code Problem: 1007 User: angrad Memory: 184K Time: 16MS Language: C Result: Accepted Source Code ----------------------------------------------- #include <stdio.h> #include <stdlib.h> typedef struct record { int index; int total; }record; int cmp( const void *a ,const void *b) { return (*(record *)a).total > (*(record *)b).total ? 1 : -1; } int main() { record sum[101]; int n, m, i, j, k, count[101], min, index; char string[101][51]; scanf("%d %d", &n, &m); memset(sum, 0, sizeof(sum)); for(i=0; i<m; i++) { sum[i].index = i; } for(i=0; i<m; i++) { scanf("%s", string[i]); memset(count, 0, sizeof(count)); for(j=0; j<n; j++) { if(j>0 && string[i][j]==string[i][j-1]) { count[j] = count[j-1]; sum[i].total += count[j]; continue; } for(k=j+1; k<n; k++) { if(string[i][k] - string[i][j] < 0) { count[j]++; } } sum[i].total += count[j]; } } qsort(sum, m, sizeof(sum[0]), cmp); for(i=0; i<m; i++) { printf("%s\n", string[sum[i].index]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator