#3325. [GESP202309 五级 C++] 第 7 题
[GESP202309 五级 C++] 第 7 题
根据下面C++代码的注释,两个横线处应分别填入( )。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool isOdd(int N) {
return N % 2 == 1;
}
bool compare(int a, int b) {
if (a % 2 == 0 && b % 2 == 1)
return true;
return false;
}
int main() {
vector<int> lstA; // lstA是一个整型向量
for (int i = 1; i < 100; i++)
lstA.push_back(i);
// 对lstA成员按比较函数执行结果排序
sort(lstA.begin(), lstA.end(), _________); // 此处填写代码1
vector<int> lstB;
for (int i = 0; i < lstA.size(); i++) // lstB成员全为奇数
if (_________) // 此处填写代码2
lstB.push_back(lstA[i]);
cout << "lstA: ";
for (int i = 0; i < lstA.size(); i++)
cout << lstA[i] << " ";
cout << endl;
cout << "lstB: ";
for (int i = 0; i < lstB.size(); i++)
cout << lstB[i] << " ";
cout << endl;
return 0;
}
{{ select(1) }}
compare和isOdd(lstA[i])compare(x1,y1)和isOddcompare和isOddcompare(x1,y1)和isOdd(lstA[i])