题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1040
一、题目要求
给出若干组数据,对每组数据排序后输出
二、题目代码
#include<iostream>
using namespace std;
int main()
{
int array[1001];//存储读入的数据
int counta; //数据组数
int countb; //每组数据的数据个数
int i, j, k; //for语句遍历用变量
int temp; //临时变量
cin >> counta;
while(counta--)
{
cin >> countb;
//读取一组数据
for(i = 0; i < countb; i++)
{
cin >> array[i];
}
//对数据进行排序
for(i = 0; i < countb - 1; i++)
{
for(j = i + 1; j < countb; j++)
{
if(array[i] > array[j])
{
//cout << "change:" << array[i] << ' ' << array[j] << endl;
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
//输出排序后的数据
for(i = 0; i < countb; i++)
{
cout << array[i];
if(i != countb - 1)
{
cout << ' ';
}
else
{
cout << endl;
}
}
}
return 0;
}
END
来源:oschina
链接:https://my.oschina.net/u/1425762/blog/299697
