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是AC了,为什么时间这么慢啊?好像我是最慢的.#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h> int re(char *s,int m) { int ret=0,i,j; for(i=0; i<m-1;i++) { for(j=i+1; j<m; j++) { if(s[i] > s[j]) ret++; } } return ret; } int cmp(const char *a,const char *b) { return (re(a,strlen(a)+1)-re(b,strlen(b)+1)); } int main(void) { int n,m,i; char *ps; char format[]="%1s"; scanf("%d %d",&n,&m); ps = malloc(m * (n + 1) * sizeof(char)); assert(ps); sprintf(format,"%%%ds",n); for(i=0; i<m; i++) { scanf(format,(ps+i*(n+1))); } qsort(ps,m,(n+1)*sizeof(char),cmp); for(i=0;i<m;i++) { printf(format,(ps+i*(n+1))); putchar('\n'); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator