首页 > 试题广场 >

程序的输出为( )

[单选题]
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
return b == 0 ? a : gcd(b, a % b);
}
struct stsort{
bool operator () (const int a, const int b) const{
if(gcd(30, a) < gcd(30, b)){
return 1;
}
else if(gcd(30, a) == gcd(30, b)){
return a < b;
}
else return 0;
}
};
int main(){
int n = 5;
priority_queue<int, vector<int>, stsort>q;
for(int i = 1; i <= n; ++i){
q.push(i);
}
for(int i = 1; i <= n; ++i){
printf("%d", q.top());
q.pop();
}
return 0;
}

程序的输出为( )
  • 53421
  • 53241
  • 12435
  • 14235
30与2/4的最大公约数不都是2吗,然后按数值小的在前,难道不是53241?
发表于 2019-09-17 10:07:08 回复(0)
按30和1/2/3/4/5的最大公约数排出的大顶堆
发表于 2019-08-15 22:15:14 回复(0)
咋算
发表于 2019-09-27 18:32:19 回复(0)