Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
92915 | 胡海峰老师 | 打印每一趟冒泡排序 | C++ | Accepted | 1 MS | 204 KB | 608 | 2024-10-06 23:25:48 |
/*Input 10 5 3 2 4 1 6 10 8 9 7 Output 10 9 8 7 6 5 4 3 2 1*/ #include <stdio.h> int a[2005] ={}; int n; void printRes() { //printf("%d--------\n",n); for(int i=1;i<=n-1;i++) printf("%d ",a[i]); printf("%d\n",a[n]); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<n;i++) { for(int j=1 ;j<=n-i;j++) { if(a[j]>a[j+1]) { int tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp; } } printRes(); } return 0; }