算法编程题:
输入一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的一个
输入:
32,231
输出:
23132
import java.util.Arrays;
import java.util.Scanner;
public class Main7
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
// 读取输入,直到没有整型数据可读
// while(cin.hasNextInt())
// while (cin.hasNextLine())
while (cin.hasNextLine())
{
String s = cin.nextLine();
String[] str = sort(s);
if (str.length > 0)
{
System.out.println(Arrays.toString(str));
}
}
}
public static String[] sort(String s)
{
String[] arr = s.split(",");
while (true)
{
boolean ok = true;
for (int j = 0; j < arr.length - 1; j++)
{
if (!checkSwap(arr[j], arr[j + 1]))
{
String tmp = "";
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
ok = false;
Syste