安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

【入门】换位置暂无标签时间限制:CC++ 1000MS其他语言 2000MS内存限制:CC++ 16MB其他语言 32MB难度:中等出题人:描述体育课上有一个班级的同学站成了一队体育老师请最高的和最矮的两位同学调换一下位置其余的同学不要动请编程实现!假设所有人的高矮都是不一样的输入描述第一行有一个整数n代表该班级的总人数n≤100第二行有n个数代表每个人的身高输出描述调换位置后的结果用例输入 1

  • 日期: 2026-12-14
  • 标签: 教育

#include #include #include

int main() { int n; std::cin >> n;

std::vector<int> heights(n);
for (int i = 0; i < n; i++) {
    std::cin >> heights[i];
}

int minIndex = std::min_element(heights.begin(), heights.end()) - heights.begin();
int maxIndex = std::max_element(heights.begin(), heights.end()) - heights.begin();

std::swap(heights[minIndex], heights[maxIndex]);

for (int i = 0; i < n; i++) {
    std::cout << heights[i] << " ";
}

return 0;
【入门】换位置暂无标签时间限制:CC++ 1000MS其他语言 2000MS内存限制:CC++ 16MB其他语言 32MB难度:中等出题人:描述体育课上有一个班级的同学站成了一队体育老师请最高的和最矮的两位同学调换一下位置其余的同学不要动请编程实现!假设所有人的高矮都是不一样的输入描述第一行有一个整数n代表该班级的总人数n≤100第二行有n个数代表每个人的身高输出描述调换位置后的结果用例输入 1

原文地址: https://www.cveoy.top/t/topic/iEV7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: Android 应用存储权限申请教程:完整指南
  • 下一篇: 分析以下代码并给出修改后的代码数据库结构:gender enum男女 not null default 男public class Students private int age;public int getAge return age; public static void mainString args throws Exception Stud

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2