C/C++代码:
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
//输入n组数
int n,cont;
int temp;
cout << "Input group number:";
cin >> n;
while(n--){ //每次输入一组数
int ch[20];
char c;
for (int i=0; i<20; i++){
scanf("%d%c",&ch[i],&c);//回车,一行表一组
if(c=='\n'){ //遇到回车退出
cont = i+1;
//cout << "cont" << cont << endl;
break;
}
//cout << "ch" << ch[i] << endl;
}
//冒泡排序
for (int j=0; j<cont; j++){
for(int i=0; i<cont-j; i++){
//cout << "ch=" << ch[i] << " ";
if (ch[i]>ch[i+1]){
temp=ch[i];
ch[i]=ch[i+1];
ch[i+1]=temp;
}
}
}
//循环输出ch数组
for (int i=0; i<cont; i++){
cout << ch[i] << " ";
}
cout << endl;
}
return 0;
}