随意输入字符串,按字母大小排序,如:abcABC,输出CcBbAa.
#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;
}