acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • tj

    #include <iostream> #include <vector> #include <algorithm> #include <iomanip> using namespace std; int main() { int n; cin >> n; vector<double> heights(n); for (int i = 0; i < n; ++i) { cin >> heights[i]; } // 找到最高和第二高的同学的位置 int max1_pos = 0, max2_pos = 0; for (int i = 1; i < n; ++i) { if (heights[i] > heights[max1_pos]) { max2_pos = max1_pos; max1_pos = i; } else if (heights[i] > heights[max2_pos] || max1_pos == max2_pos) { max2_pos = i; } } // 交换最高和最左边 swap(heights[max1_pos], heights[0]); // 交换第二高和最右边,但要确保第二高没有被交换到最左边 if (max2_pos == 0) { max2_pos = max1_pos; } swap(heights[max2_pos], heights[n - 1]); // 输出结果 for (int i = 0; i < n; ++i) { cout << fixed << setprecision(2) << heights[i]; if (i != n - 1) { cout << " "; } } cout << endl; return 0; }

    userId_undefined

    AAA秋褲批發lexora_哥

    小有名气题解仙人时空双修者秩序白银传道者
    2阅读
    0回复
    1点赞
  • 题解7

    #include <iostream> #include <vector> #include <algorithm> #include <iomanip> using namespace std; int main() { int n; cin >> n; vector<double> heights(n); for (int i = 0; i < n; ++i) { cin >> heights[i]; } }

    userId_undefined

    霄

    时空双修者荣耀黄金
    10阅读
    0回复
    0点赞
  • 题解

    userId_undefined

    zsy

    7月全勤卷王题解仙人出道萌新时间刺客时空双修者秩序白银
    1阅读
    0回复
    0点赞
首页