BC - A problem of sorting(模拟题)

来源:互联网 发布:monaco 字体 windows 编辑:程序博客网 时间:2024/05/17 22:26

A problem of sorting

 
 Accepts: 445
 
 Submissions: 1706
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)
输入描述
第一行包含一个正整数T(T \leq 5)T(T5),表示数据组数。对于每组数据,第一行包含一个正整数n(1 \leq n \leq 100)n(1n100),表示人数,接下来n行,每行包含一个姓名和生日年份(1900-2015),用一个空格隔开。姓名长度大于0且不大于100。注意姓名中只包含字母,数字和空格。
输出描述
对于每组数据,输出nn行姓名。
输入样例
21FancyCoder 19962FancyCoder 1996xyz111 1997
输出样例
FancyCoderxyz111FancyCoder
#include <map>#include <set>#include <cstdio>#include <cmath>#include <cstring>#include <vector>#include <queue>#include <iostream>#include <string>#include <sstream>#include <cstdlib>#include <ctime>#include <cctype>#include <algorithm>using namespace std;#define pb push_back#define mp make_pair#define fillchar(a, x) memset(a, x, sizeof(a))#define copy(a, b) memcpy(a, b, sizeof(a))#define S_queue<P> priority_queue<P, vector<P>,greater<P> >typedef long long LL;typedef pair<int, string > PII;typedef unsigned long long uLL;template<typename T>void print(T* p, T* q, string Gap = " ") {    int d = p < q ? 1 : -1;    while(p != q) {        cout << *p;        p += d;        if(p != q) cout << Gap;    }    cout << endl;}template<typename T>void print(const T &a, string bes = "") {    int len = bes.length();    if(len >= 2)cout << bes[0] << a << bes[1] << endl;    else cout << a << endl;}void read(char * str, int &age){    char st[100 + 5];    gets(st);    int len = strlen(st);    age = atoi(st + len - 4);    for(int i = 0;i < len - 4 - 1;i ++){        str[i] = st[i];    }    str[len - 4 - 1] = '\0';}const int INF = 0x3f3f3f3f;const int MAXM = 1e5;const int MAXN = 3e5 +5;priority_queue<PII> que;int T, n, age;char str[100 + 5];int main(){   // freopen("D://imput.txt", "r", stdin);    cin >> T;    while(T --){        while(!que.empty()) que.pop();        cin >> n;        getchar();        for(int i = 0;i < n;i ++){            read(str, age);            que.push(PII(age, str));        }        while(!que.empty()){            print(que.top().second);            que.pop();        }    }    return 0;}


0 0