解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct people
{
char sex[7];
float height;
};
int main()
{
struct people* x;
int n,i,j=0,k=0,l;
float a[40], b[40];
scanf("%d", &n);
x = (struct people *)malloc(n * sizeof(struct people));
for (i = 0; i < n; i++)
scanf("%s %f", x[i].sex, &x[i].height);
for (i = 0; i < n; i++)
{
if (strcmp(x[i].sex, "male") == 0)
{
a[j] = x[i].height;
j++;
}
if (strcmp(x[i].sex, "female") == 0)
{
b[k] = x[i].height;
k++;
}
}
for (i = 0; i < j - 1; i++)
{
for (l = 0; l < j - i - 1; l++)
{
if (a[l] > a[l + 1])
{
float temp;
temp = a[l];
a[l] = a[l + 1];
a[l + 1] = temp;
}
}
}
for (i = 0; i < k - 1; i++)
{
for (l = 0; l < k - i - 1; l++)
{
if (b[l] < b[l + 1])
{
float temp;
temp = b[l];
b[l] = b[l + 1];
b[l + 1] = temp;
}
}
}
for (i = 0; i < j; i++)
printf("%.2f ", a[i]);
for (i = 0; i < k; i++)
printf("%.2f ", b[i]);
return 0;
}
0.0分
2 人评分
【数组的距离】 (C语言代码)浏览:787 |
最小公倍数 (C语言代码)浏览:894 |
【亲和数】 (C语言代码)浏览:908 |
简单的a+b (C语言代码)浏览:878 |
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:710 |
【偶数求和】 (C语言代码)浏览:460 |
图形输出 (C语言代码)浏览:1019 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:536 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:608 |
统计立方数 (C语言代码)浏览:890 |