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" //该函数用来每组数据中的逆序对个数 int cal_inversions(char* v[],int n) { int i,j,k=0; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(*v[i]>*v[j]) k++; return(k); } void main() { int m,n,i,j,k[100],t[50]; char mn[100][50]; scanf("%d%d",&m,&n); //用来求每个字符串所对应的逆序对个数,记入k[]中 for(i=0;i<m;i++) { scanf("%s",mn+i); k[i]=cal_inversions(mn+i,n); } //对逆序对个数进行排序,并将对应下标绑定结果到t[], for(i=0;i<n;i++) { int temp=0; for(j=i+1;j<n;j++) if(k[i]>k[j]) i=j,temp=i; t[i]=temp; } //打印结果, for(i=0;i<m;i++) printf("%s\n",mn[t[i]]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator