第20822题 判断
判断该C++代码执行后的输出是否为"0 5 1 6 2 3 4"

给定以下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;
}
A

正确

B

错误

提交0次 正确率0.00%
答案解析