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 |
求助,老是Wrong Answer以下是小弟1007的代码,其中用到了STL qsort排序函数,其本思想是通过该函数实现字符串按inversion值从小到大排序,可怎么老出是Wrong Answer呢? #include<iostream> #include<algorithm> using namespace std; int inversion(const char* s) { int n=strlen(s); int result=0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(s[i]>s[j]) result++; return result; } int compare(const void* s1,const void* s2) { if(inversion((char*)s1)>=inversion((char*)s2)) return true; else return false; } int main() { char input[100][50]; int n,m,i; scanf("%d%d",&n,&m); for(i=0;i<m;i++){ scanf("%s",input[i]); } qsort((void*)input,m,sizeof(input[0]),compare); for(i=0;i<m;i++) printf("%s\n",input[i]); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator