主页
试题仓库
题目列表
试题分类
经典教材
竞赛作业
竞赛列表
提交状态
图灵学院
TuringMOOC
图灵书屋
图灵商城
图灵实验室
图灵会员
历史荣誉
支持我们
图灵IDE
用户/排名
AOJ排名
实名认证
请登录
常用链接
AOJ考试平台
老赵的Gitee代码
编译原理模拟考试平台
Java技术手册
FCC网站
菜鸟网
在线工具箱
字节豆包GPT
代码可视化
力扣网
牛客网
洛谷
杭电OJ
CodeForce
隐藏编译器
Problem 2651 --2_A : Bubble Sort
2651: 2_A : Bubble Sort
上一题
正确率: $76.57\%$
下一题
Time Limit
$1$ 秒/Second(s)
Memory Limit
$512$ 兆字节/Megabyte(s)
提交总数
$798$
正确数量
$611$
"
裁判形式
标准裁判/Standard Judge
我的状态
尚未尝试
难度
分类标签
排序
×
为本题添加算法分类(请不要超过5个)
当前分类(单击移除):
排序
单击选择分类:
Description
<p> Bubble Sort </p> <p> Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <p> BubbleSort(A) </p> <p> 1 for i = 0 to A.length-1 </p> <p> 2 for j = A.length-1 downto i+1 </p> <p> 3 if A[j] < A[j-1] </p> <p> 4 swap A[j] and A[j-1] </p> <p> Note that, indices for array elements are based on 0-origin. </p> <p> Your program should also print the number of swap operations defined in line 4 of the pseudocode. </p>
Input
<p> The first line of the input includes an integer N, the number of elements in the sequence. </p> <p> In the second line, N elements of the sequence are given separated by spaces characters. </p>
Output
<p> The output consists of 2 lines. </p> <p> In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. </p> <p> In the second line, please print the number of swap operations. </p>
Sample Input
5 5 3 2 4 1
Sample Output
1 2 3 4 5 8
提示
1 ≤ N ≤ 100
推荐代码
查看2651 所有题解
上传题解视频得图灵币
本题记录
用 户(点击查看用户)
运行号(点击购买题解)
时 间
算法最快[$0 $ms]
0
内存最少[$0 $KB]
0
第一AC
0
第一挑战
0
赛题来源
会津大学《挑战数据结构与算法》
挑战数据结构与算法
AOJ
Please Login