poj1007

题目意思是说让你给一些字符串排序

每个字符串有个附带值 这个附带值的计算方法是这样的

每个字符右边所有比它小的字符的个数之和

然后按照这个附带值从小到大对字符串排序

字符串的长度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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值