Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

晒一下自己的代码

Posted by 99731 at 2012-05-19 09:22:59 on Problem 1007
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator