字母排序问题,例如输入ageAGE,输出GgEeAa
求大神解答
程序代码:
#include<stdio.h> #include<string.h> void sort(char a[], int n) { int i, j; for (i = 0; i < n - 1; i++) { for (j = i + 1; j< n; j++) { if (a[i] < a[j]) { char temp; if ((a[j] >= 'a') && (a[i] <= 'a')) { if ((a[i] - 'A') < (a[j] - 'a')) { continue; } } temp = a[i]; a[i] = a[j]; a[j] = temp; } else { char temp; if ((a[i] >= 'a') && (a[j] <= 'a')) { if ((a[i] - 'a') <= (a[j] - 'A')) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } } } } int main() { char a[] = "ageAGE"; sort(a, strlen(a)); printf("%s\n",a); return 0; }