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<iostream> #include<memory> using namespace std; int n,m; int cal(char a[]) { int result=0; int i,j; if(strlen(a)==1) return 0; for(i=0;i<=n-2;i++) for(j=i+1;j<=n-1;j++) if(a[i]>a[j]) result++; return result; } int main() { char array[1000][500]; int sort[1000]; memset(array,0,sizeof(array)); int i,j; while(cin>>n>>m) { for(i=1;i<=m;i++) { cin>>array[i]; sort[i]=cal(array[i]); } char temp[51],tempno; for(i=1;i<=m-1;i++) for(j=1;j<=m-i;j++) if(sort[j]>sort[j+1]) { strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); tempno=sort[j]; sort[j]=sort[j+1]; sort[j+1]=tempno; } for(i=1;i<=m;i++) cout<<array[i]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator