题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> int main() { char str[1000]; while(gets(str)) { int len = strlen(str); char out[1000] = { '0' }; int out_index = 0; memset(out, 'A', sizeof(out)); for (int i = 0; i<26; i++) { char point = 'a' + i; for (int j = 0; j<len; j++) { if ((str[j] == point) || (str[j] == (point + 'A' - 'a'))) { while (!(((out[out_index] >= 'a') && (out[out_index] <= 'z')) || ((out[out_index] >= 'A') && (out[out_index] <= 'Z')))) { //这个位置是可以存放的 out_index++; } out[out_index++] = str[j]; } else if (!(((str[j] >= 'a') && (str[j] <= 'z')) || ((str[j] >= 'A') && (str[j] <= 'Z')))) { out[j] = str[j]; } } } for (int j = 0; j<len; j++) { printf("%c", out[j]); } printf("\n"); } }