|
@@ -0,0 +1,65 @@
|
|
|
+#include <stdio.h>
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+// 辅助函数:交换两个字符
|
|
|
+void swap(char *a, char *b) {
|
|
|
+ char temp = *a;
|
|
|
+ *a = *b;
|
|
|
+ *b = temp;
|
|
|
+}
|
|
|
+
|
|
|
+// 辅助函数:快速排序
|
|
|
+void quicksort(char arr[], int low, int high) {
|
|
|
+ if (low < high) {
|
|
|
+ int pivot = arr[high];
|
|
|
+ int i = (low - 1), j;
|
|
|
+ for (j = low; j < high; j++) {
|
|
|
+ if (arr[j] < pivot) {
|
|
|
+ i++;
|
|
|
+ swap(&arr[i], &arr[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ swap(&arr[i + 1], &arr[high]);
|
|
|
+ int pi = i + 1;
|
|
|
+
|
|
|
+ quicksort(arr, low, pi - 1);
|
|
|
+ quicksort(arr, pi + 1, high);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int main() {
|
|
|
+ char input[1000];
|
|
|
+ char output[1000];
|
|
|
+
|
|
|
+ // 读取输入字符串
|
|
|
+ if (fgets(input, sizeof(input), stdin) == NULL) {
|
|
|
+ printf("\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 去掉换行符
|
|
|
+ input[strcspn(input, "\n")] = 0;
|
|
|
+
|
|
|
+ int len = strlen(input);
|
|
|
+ if (len == 0) {
|
|
|
+ printf("\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对字符串进行快速排序
|
|
|
+ quicksort(input, 0, len - 1);
|
|
|
+
|
|
|
+ // 删除重复字符
|
|
|
+ int j = 0, i;
|
|
|
+ for (i = 0; i < len; i++) {
|
|
|
+ if (i == 0 || input[i] != input[i - 1]) {
|
|
|
+ output[j++] = input[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ output[j] = '\0';
|
|
|
+
|
|
|
+ // 输出结果
|
|
|
+ printf("%s\n", output);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|