编程语言单选难度 3真题改编 · 2024
3464. 下面 C++ 程序的运行结果为()
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
return a.second < b.second;
}
int main() {
std::vector<std::pair<int, int>> v_p;
v_p.emplace_back(1, 2);
v_p.emplace_back(2, 1);
v_p.emplace_back(3, 4);
v_p.emplace_back(4, 3);
sort(v_p.begin(), v_p.end(), cmp);
for (auto t : v_p)
{
std::cout << t.first << " " << t.second << std::endl;
}
return 0;
}
练习本题 ›
算法与数据结构栈单选难度 3真题改编 · 2024
3470. 下列程序的运行结果是( )
import java.util.*;
class Test{
public static void main(String[] args){
int[] pushA={1,2,4,5,3,6};
int[] popA1={4,5,2,3,1,6};
int[] popA2={4,6,5,2,3,1};
boolean res1=IsPopOrder(pushA,popA1);
boolean res2=IsPopOrder(pushA,popA2);
System.out.println(res1);
System.out.println(res2);
}
public static boolean IsPopOrder(int[] pushA,int[] popA){
if(pushA.length==0||popA.length==0) return false;
Stack<Integer> st=new Stack<Integer>();
int index=0;
for(int i=0;i<pushA.length;i++){
st.push(pushA[i]);
while(!st.empty()&&st.peek()==popA[index]){
st.pop();
index++;
}
}
return st.empty();
}
}
练习本题 ›
编程语言单选难度 3真题改编 · 2024
3477. 执行以下程序,如果希望输出 df 对象中 x 列数据大于其平均值的所有行,下列选项中,做法正确的一项是() import pandas as pd
df = pd.DataFrame({'x':[1, 2, 3, 4], 'y':[3, 4, 5, 6]})
a = df.x.mean()
练习本题 ›