# 字符串排序

用main方法排序（按首字母或按字符串长度）
要求：
①输出原数组和排序后的数组
②若有“，”“.”不能进行排序，并将不符合排序要求的数组打印出来
③不能用API,可用选择、冒泡、快速

## template

```java
import java.util.Scanner;
class Untitled {
   public static void main(String[] args) {
	  int num;
	  System.out.println("请输入数组元素长度：");
	  Scanner in = new Scanner(System.in);
	  num = in.nextInt();
	  System.out.println("请输入字符串：");
	  String str[] = new String[num];
	  for (int count = 0; count < num; count++) {
		 str[count] = in.next();
	  }
	  in.close();
	  System.out.println("before sorting:");
	  int c = 0;
	  for (int i = 0; i < num; i++) {
		 if (str[i].contains(",") || str[i].contains("."))
			c++;
		 System.out.println(str[i]);
	  }
	  for (int i = 0; i < num - 1; i++) {
		 int min = i;
		 for (int j = i + 1; j < num; j++) {
			if (str[min].contains(",") || str[min].contains("."))
			   min = j;
			else if (str[j].compareTo(str[min]) < 0 && !str[j].contains(",") && !str[j].contains("."))
			   min = j;
		 }
		 if (min != i) {
			String t = str[i];
			str[i] = str[min];
			str[min] = t;
		 }
	  }
	  System.out.println("after sorting:");
	  for (int i = 0; i < num - c; i++)
		 System.out.println(str[i]);
	  System.out.println("invalid items:");
	  for (int i = num - c; i < num; i++)
		 System.out.println(str[i]);
   }
}
```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```