题解 | 字符串排序
#include <stdio.h>
#include <string.h>
/* 奇怪了,用调试工具是好的,但是自测的时候提示段错误,何解? */
#define LEN 1001
char uptolower(char a)
{
if (a >= 'A' && a <= 'Z') {
return a - 'A' + 'a';
}
return a;
}
int isnotletters(char a)
{
if ((a >= 'A' && a <= 'Z') || (a >= 'a' && a <= 'z')) {
return 0;
} else {
return 1;
}
}
int main() {
char input[LEN];
char output[LEN];
int index;
int len;
gets(input);
len = strlen(input);
for (int i = 'a'; i < 'z'; i++) {
if (input[index] == 0) {
break;
}
for (int j = 0; j < len; j++) {
if (input[index] == 0) {
break;
}
while (isnotletters(input[index])) {
output[index] = input[index];
index++;
}
if (input[j] == i || uptolower(input[j]) == i) {
output[index++] = input[j];
}
}
}
printf("%s", output);
return 0;
}