学校oj过不去,希望大家解答。。

问题遇到的现象和发生背景

img

问题相关代码,请勿粘贴截图
class sort12
{
public:
    bool operator()(grade&g1, grade&g2)
    {
        if (g1.m_grade != g2.m_grade)//先总分按大的来
        {
            return g1.m_grade > g2.m_grade;
        }
        else if (g1.m_grade == g2.m_grade)//总分相同下
        {
            if (g1.m_yuwen == g2.m_yuwen)//语文再相同就按学号小的先
            {
                return g1.m_number < g2.m_number;
            }
            else//语文高的排的前
            {
                return g1.m_yuwen > g2.m_yuwen;
            }
        }
        
    
    }


};
//1271: 奖学金
void test77()
{
    int n;
    vector<grade>v1;
    while (cin >> n)
    {
        int hao = 1;
        for (int i = 0; i < n; i++)
        {
            int a, b, c;
            cin >> a >> b >> c;
            int sum = a + b + c;
            
            grade g(hao, sum,a);
            v1.push_back(g);
            hao++;
        }
        int count = 0;
        sort(v1.begin(), v1.end(), sort12());
        for (vector<grade>::iterator it = v1.begin(); it != v1.end(); it++)
        {
            if (count != 5)
            {
                cout << it->m_number << " " << it->m_grade << endl;
                count++;
            }
            if (count == 5)
            {
                break;
            }
        }
        v1.clear();
    

    }







}
int main()
{
    test77();

}

一直过不去,不知道问题在哪里。


// Requires C++17

#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>

int main()
{
    std::size_t n;
    std::vector<std::tuple<int, float, float, float>> grades;
    std::cin >> n;
    for (std::size_t i = 0; i < n; i++)
    {
        std::size_t no = i + 1;
        float a, b, c;
        std::cin >> a >> b >> c;
        grades.push_back({no, a, b, c});
    }
    std::sort(grades.begin(), grades.end(), [](const auto &lhs, const auto &rhs)
              {
                  auto [no1, a1, b1, c1] = lhs;
                  auto [no2, a2, b2, c2] = rhs;
                  auto sum1 = a1 + b1 + c1;
                  auto sum2 = a2 + b2 + c2;
                  if (sum1 > sum2)
                      return true;
                  if (sum1 < sum2)
                      return false;
                  if (a1 > a2)
                      return true;
                  if (a1 < a2)
                      return false;
                  return no1 < no2;
              });
    int count = 0;
    for (auto [no, a, b, c] : grades)
    {
        std::cout << no << ' ' << (a + b + c) << std::endl;
        if (++count >= 5)
            break;
    }

    return 0;
}