{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "81a61e783574465a8a4caad87533ac75",
  "keywords": "算法初阶,快速排序,快速排序分析,排序和顺序统计量",
  "title": "字符串排序",
  "desc": [
    {
      "content": "\n用main方法排序（按首字母或按字符串长度）\n要求：\n①输出原数组和排序后的数组\n②若有“，”“.”不能进行排序，并将不符合排序要求的数组打印出来\n③不能用API,可用选择、冒泡、快速",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "import java.util.Scanner;\nclass Untitled {\n   public static void main(String[] args) {\n\t  int num;\n\t  System.out.println(\"请输入数组元素长度：\");\n\t  Scanner in = new Scanner(System.in);\n\t  num = in.nextInt();\n\t  System.out.println(\"请输入字符串：\");\n\t  String str[] = new String[num];\n\t  for (int count = 0; count < num; count++) {\n\t\t str[count] = in.next();\n\t  }\n\t  in.close();\n\t  System.out.println(\"before sorting:\");\n\t  int c = 0;\n\t  for (int i = 0; i < num; i++) {\n\t\t if (str[i].contains(\",\") || str[i].contains(\".\"))\n\t\t\tc++;\n\t\t System.out.println(str[i]);\n\t  }\n\t  for (int i = 0; i < num - 1; i++) {\n\t\t int min = i;\n\t\t for (int j = i + 1; j < num; j++) {\n\t\t\tif (str[min].contains(\",\") || str[min].contains(\".\"))\n\t\t\t   min = j;\n\t\t\telse if (str[j].compareTo(str[min]) < 0 && !str[j].contains(\",\") && !str[j].contains(\".\"))\n\t\t\t   min = j;\n\t\t }\n\t\t if (min != i) {\n\t\t\tString t = str[i];\n\t\t\tstr[i] = str[min];\n\t\t\tstr[min] = t;\n\t\t }\n\t  }\n\t  System.out.println(\"after sorting:\");\n\t  for (int i = 0; i < num - c; i++)\n\t\t System.out.println(str[i]);\n\t  System.out.println(\"invalid items:\");\n\t  for (int i = num - c; i < num; i++)\n\t\t System.out.println(str[i]);\n   }\n}",
    "language": "java"
  },
  "node_id": "dailycode-2bd314f30cd143a5acaf9847ce64e8d1",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470190"
}