zoukankan      html  css  js  c++  java
  • PTA 乙级 1055 集体照 (25分) C++

     好难啊,困了

     1 #include<iostream>
     2 #include<vector>
     3 #include<algorithm>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int n, k, m, h;
    10     cin >> n >> k;
    11     m = n / k;
    12     vector<pair<string,int>>student(n);
    13     for (int i = 0; i < n; i++)
    14         cin>>student[i].first>>student[i].second;
    15     sort(student.begin(), student.end(), [](pair<string,int>& a, pair<string, int>& b) {
    16         return a.second != b.second ? a.second < b.second : a.first > b.first;});
    17     bool flag = true;
    18     for (int i = (k - 1) * m; i >= 0; i -= m){
    19         int num = m;
    20         if (flag){
    21             num = n - i;
    22             flag = false;
    23         }
    24         int s = num % 2 ? 2 : 1;
    25         int e = num % 2 ? 1 : 2;
    26         for (int j = s; j < num; j += 2)
    27             cout << student[i + j - 1].first << " ";
    28         for (int j = num; j >= e; j -= 2)
    29             cout << student[i + j - 1].first<<(j > e?" ":"");
    30         cout << endl;
    31     }
    32     return 0;
    33 }

    默默地一点点变强,细节决定成败
  • 相关阅读:
    C语言I博客作业09
    C语言I博客作业08
    C语言I博客作业07
    C语言I博客作业06
    C语言I博客作业05
    C语言II博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
    c语言学期总结
  • 原文地址:https://www.cnblogs.com/SCP-514/p/13548031.html
Copyright © 2011-2022 走看看