本题思路:输入一串字符串,对奇数位置和偶数位置分别排序
#include <stdio.h>
int str[10000];
int main()
{
int date,temp;
scanf("%d",&date);
int j,r;
for(j = 0; j < date;j++)
{
scanf("%d",&str[j]);
}
for(j = 0;j < date-2;j+=2) //奇数位置从小到大排序
for(r = 0;r < date-2-j;r+=2)
{
if(str[r] > str[r+2])
{
temp = str[r];
str[r] = str[r+2];
str[r+2] = temp;
}
}
for(j = 1;j < date-1;j+=2)//偶数位置从大到小排序
for(r = 1;r < date-1-j;r+=2)
{
if(str[r] < str[r+2])
{
temp = str[r];
str[r] = str[r+2];
str[r+2] = temp;
}
}
for(j = 0;j < date-1;j++)
printf("%d ",str[j]);
printf("%d\n",str[date-1]);
return 0;
}