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 |
表示就不理解了 明明和别人的想法是一样的。。。为啥我tle= =求大牛指导#include<cstdio> #include<cstring> #include<iostream> #include<cstdlib> #include <algorithm> using namespace std; char in[51][101]; int m,n,temp; int cal(char a[]) { int result=0; int len=n; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(a[i]>a[j]) result++; } } return result; } int cmp(const void *e1,const void *e2) { int *p1,*p2; p1=(int *)e1; p2=(int *)e2; return *p1-*p2; } int main() { int result[51],order[51]; while(cin>>n>>m) { for(int i=0;i<m;i++) { result[i]=0; } for(int i=0;i<m;i++) { cin>>in[i]; order[i]=result[i]=cal(in[i]); } qsort(order,m,sizeof(int),cmp); for(int i=0;i<m;i++) { for(int j=0;j<m;j++) if(result[j]==order[i]) { cout<<in[j]<<endl; result[j]=-1; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator