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 |
晒一下自己的代码#include <iostream> #include <algorithm> using namespace std; int unsortedness(char *a) { int i,j,sum=0; for(i=0;a[i]!='\0';i++) { for(j=i+1;a[j]!='\0';j++) if(a[i]>a[j])sum++; } return sum; } int cmp(int &a,int &b) { return (a)>(b)?0:1; } int main() { char ch[101][51]; int sum[101],order[101]; int n,m,j,i; cin>>n>>m; for( j=0;j<m;j++){ cin>>ch[j]; sum[j]=order[j]=unsortedness(ch[j]); } sort(order,order+m,cmp); for(i=0;i<m;i++) { for(j=0;j<m;j++) if(sum[j]==order[i]) { cout<<ch[j]<<endl; sum[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