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 |
怎麼會WA呢??#include <stdio.h> #include <string.h> #include <stdlib.h> struct DNA{ char str[51]; int sort; }d[101]; int cmp(const void *a,const void *b) { if( ((DNA*)a)->sort != ((DNA*)b)->sort ) return ((DNA*)a)->sort > ((DNA*)b)->sort;//sort從小到大 return 1;// //return strcmp( ((DNA*)a)->str,((DNA*)b)->str );//字典升序 } int main() { freopen("data.in","r",stdin); freopen("data.out","w",stdout); int n,m,i,j,k; scanf("%d%d",&n,&m); getchar(); for(i=0;i<m;i++) gets(d[i].str); for(i=0;i<m;i++) { d[i].sort=0; for(j=0;j<n;j++) for(k=j+1;k<n;k++) if(d[i].str[j]>d[i].str[k]) d[i].sort++; } qsort(d,m,sizeof(d[0]),cmp); for(i=0;i<m;i++) printf("%s\n",d[i].str,d[i].sort); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator