冒泡排序 hdu 1040(水题)
As Easy As A+BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 72343 Accepted Submission(s): 30730 Problem Description These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.
Input Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line.
Output For each case, print the sorting result, and one line one case.
Sample Input
2 3 2 1 3 9 1 4 7 2 5 8 3 6 9
Sample Output
1 2 3 1 2 3 4 5 6 7 8 9 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
int a[1010];
while(cin >> n){
while(n--){
cin >> m;
int i,j,t;
for(i = 0;i < m;i++)
cin >> a[i];
for(i = 0;i < m;i++)
for(j = 0;j < m-i-1;j++)
if(a[j] > a[j+1]){
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
for(i = 0;i < m;i++){
cout << a[i] << (i==m-1?'\n':' ');
}
}
}
return 0;
}
推荐阅读
-
HDU - 4802 - GPA (水题)
-
HDU4461 UVALive6379 The Power of Xiangqi【水题】
-
【水题】HDU-1037 Keep on Truckin'
-
http://acm.hdu.edu.cn/showproblem.php?pid=1020大水题一个疑惑释
-
http://acm.hdu.edu.cn/showproblem.php?pid=1020大水题一个疑惑释
-
冒泡排序 hdu 1040(水题)
-
2018 hdu 1011/6308 Time Zone 一道水题的学习过程!
-
HDU - 4802 - GPA (水题)
-
HDU 6159 cable cable cable (规律水题)
-
(HDU):6242 Geometry Problem (几何水题)