HDU 5702 Solving Order (水题,排序)

题意:给定几种不同的颜色和它的权值,按它的权值排序。

析:排序。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
struct node{
    string s;
    int id;
    bool operator < (const node &p) const{
        return p.id < id;
    }
};
vector<node> v;

int main(){
    int T;  cin >> T;
    while(T--){
        scanf("%d", &n);
        v.clear();
        node u;
        for(int i = 0; i < n; ++i){
            cin >> u.s >> u.id;
            v.push_back(u);
        }
        sort(v.begin(), v.end());
        for(int i = 0; i < v.size(); ++i)
            if(!i)  cout << v[i].s;
            else  cout << " " << v[i].s;
        cout << endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5719322.html