轻松的编程学习
首页
下载应用
登录 / 注册
菜单
给冒泡加上计数
👁️ 1 人浏览
💬 0 人评论
❤️ 添加收藏
补全
bubble_stat
:数出比较次数和交换次数,用 / 拼起来输出。
(本题用
g++ -std=c++17 -O0
编译。)
提交你的答案
请登录后提交答案。
去登录
← 插入排序比了几次挪了几次
两种排序的比较次数差多少 →
更多题目
改成"你好,有词"
输出"100 分"
把年龄改成 20
输出学习天数 30
修复:给文字加引号
修复:补上右括号
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
#include <algorithm> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; string bubble_stat(vector<int> b) { int n = (int)b.size(), cmps = 0, swaps = 0; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { // TODO: 每比一次 cmps 加一;真的交换了才把 swaps 加一 if (b[j] > b[j + 1]) swap(b[j], b[j + 1]); } } return to_string(cmps) + "/" + to_string(swaps); } int main() { cout << bubble_stat({17, 24, 15, 13, 23}) << endl; }
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
🔒
登录并作答后可看讨论