1007.cpp

来自「pku acm 1001,share it and enjoy it acm.」· C++ 代码 · 共 55 行

CPP
55
字号
// 1007.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

class sss
{
public:
	char ch[51];
	int key;
	 friend bool operator<(const sss a,const sss b)
	{ 
		return ((a.key)<(b.key));
	}

};
int val_key(char *ch,int len)
{
	int i,j,t=0;
	for(i=0;i<len;i++)
	{
		for(j=i+1;j<len;j++)
		{
			if(ch[i]>ch[j])
			{t++;}
		}
	}
	return t;
}

void main()
{
	
	int len,num;
	cin>>len>>num;
	int i;
    sss p[101];
	for(i=0;i<num;i++)
	{
		cin>>p[i].ch;
		(p[i]).ch[len]='\0';
		p[i].key=val_key(p[i].ch,len);
		
	}
	stable_sort(p,p+num);
	for(i=0;i<num;i++)
	{
		cout<<p[i].ch<<endl;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?