经常有点小迷糊
2020-05-26 19:16
采纳率: 96.7%
浏览 123

小白求助:各位大神们,有谁知道这两个测试点错在哪里吗?小小白求助!

各位大神们,有谁知道这两个测试点错在哪里吗?小小白求助!
图片说明
图片说明

#include <iostream>
using namespace std;
int main()
{
    /*总数*/
    int n;
    cin >> n;
    /*学号*/
    int* value_studentnumber = new int[n];
    /*语文*/
    int* value_student_Chinese = new int[n];
    /*数学*/
    int* value_student_math = new int[n];
    /*英语*/
    int* value_student_English = new int[n];
    /*总分*/
    int* sum = new int[n];
    for (int i = 0; i < n; i++)
    {
        value_studentnumber[i] = i + 1;
        cin >> value_student_Chinese[i] >> value_student_math[i] >> value_student_English[i];
        sum[i] = value_student_Chinese[i] + value_student_English[i] + value_student_math[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (sum[j] < sum[j + 1])
            {
                int temp = sum[j];
                sum[j] = sum[j + 1];
                sum[j + 1] = temp;
                int temp1 = value_studentnumber[j];
                value_studentnumber[j] = value_studentnumber[j + 1];
                value_studentnumber[j + 1] = temp1;
            }
            if (sum[j] == sum[j + 1] && value_student_Chinese[j] < value_student_Chinese[j + 1])
            {
                int temp = sum[j];
                sum[j] = sum[j + 1];
                sum[j + 1] = temp;
                int temp1 = value_studentnumber[j];
                value_studentnumber[j] = value_studentnumber[j + 1];
                value_studentnumber[j + 1] = temp1;
            }
            if (sum[j] == sum[j + 1] && value_student_Chinese[j] == value_student_Chinese[j + 1] && value_studentnumber[j] > value_studentnumber[j + 1])
            {
                int temp = sum[j];
                sum[j] = sum[j + 1];
                sum[j + 1] = temp;
                int temp1 = value_studentnumber[j];
                value_studentnumber[j] = value_studentnumber[j + 1];
                value_studentnumber[j + 1] = temp1;
            }
        }
    }
    for (int i = 0; i < 5; i++)
    {
        cout << value_studentnumber[i] << " " << sum[i] << endl;
    }
    return 0;
}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • 智者知已应修善业 2020-05-27 10:13
    最佳回答

    这样的题目用类数组执行排序比较容易些。

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题