#GESP1900. [GESP]L5-202309-Q1900-J

[GESP]L5-202309-Q1900-J

下面的 C++ 代码执行后将输出 0 5 1 6 2 3 4。

#include <iostream>
#include <algorithm>
using namespace std;

bool compareModulo5(int a, int b) {
    return a % 5 < b % 5;
}

int main() {
    int lst[7];
    for (int i = 0; i < 7; i++)
        lst[i] = i;

    // 对序列所有元素按compareModulo5结果排序
    sort(lst, lst + 7, compareModulo5);

    for (int i = 0; i < 7; i++)
        cout << lst[i] << " ";
    cout << endl;
    return 0;
}

{{ select(1) }}

  • 正确
  • 错误