题目链接

https://www.patest.cn/contests/gplt/L1-030

思路
用三个 Vector 来分别存放 整个排名,以及男生的单独排名和女生的单独排名
从整个的排名 从上到下 遍历到 n / 2 的位置 如果第一个出来的是 男生, 那么就从女生最后一名出来 然后pop_back ,如果是女生,就从男生最后一名出来,然后pop_back

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>

using namespace std;
typedef long long LL;

const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;

const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

struct Node
{
    string name;
    int sex;
}temp;

int main()
{
    int n;
    cin >> n;
    vector <Node> F, M, V;
    F.clear();
    M.clear();
    V.clear();
    for (int i = 0; i < n; i++)
    {
        cin >> temp.sex >> temp.name;
        if (temp.sex == 1)
            M.push_back(temp);
        else
            F.push_back(temp);
        V.push_back(temp);
    }
    n /= 2;
    for (int i = 0; i < n; i++)
    {
        if (V[i].sex == 1)
        {
            cout << V[i].name << " " << F[F.size() - 1].name << endl;
            F.pop_back();
        }
        else
        {
            cout << V[i].name << " " << M[M.size() - 1].name << endl;
            M.pop_back();
        }
    }
}

相关文章:

  • 2022-01-31
  • 2021-12-08
  • 2022-02-18
  • 2022-01-27
  • 2021-12-24
  • 2021-11-19
猜你喜欢
  • 2021-09-16
  • 2021-10-28
  • 2022-12-23
  • 2021-11-29
  • 2021-08-15
  • 2021-08-28
相关资源
相似解决方案