题目意思是说让你给一些字符串排序
每个字符串有个附带值 这个附带值的计算方法是这样的
每个字符右边所有比它小的字符的个数之和
然后按照这个附带值从小到大对字符串排序
字符串的长度50
(n^2)/2就能搞定附带值 排序我用优先队列的
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
using namespace std;
struct node{
char s[60];
int x;
friend bool operator<(node a,node b){
return a.x>b.x;
}
}p;
priority_queue<node>q;
int main(){
while(!q.empty()){
q.pop();
}
int m,n;
char str[60];
cin>>m>>n;
while(n--){
cin>>str;
int x=0;
for(int i=0;i<strlen(str);i++){
for(int j=i+1;j<strlen(str);j++){
if(str[i]>str[j]){
x++;
}
}
}
strcpy(p.s,str);
p.x=x;
q.push(p);
}
while(!q.empty()){
cout<<q.top().s<<endl;
q.pop();
}
return 0;
}