csu 1079

排序

# include <stdio.h>
typedef struct record
{
float h, w;
char name[50];
} stu;
int main()
{
int N, i, j;
stu st[50], tmp;

//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);

while (1)
{
scanf("%d", &N);
if (N == 0) break;
for (i = 0; i < N; ++i)
scanf("%s%fm%fkg\n", &st[i].name, &st[i].h, &st[i].w);

for (j = 1; j < N; ++j)
{
tmp = st[j];
i = j - 1;
while (i>=0 && st[i].h<tmp.h || (st[i].h==tmp.h && st[i].w<tmp.w))
{
st[i+1] = st[i];
--i;
}
st[i+1] = tmp;
}

for (i = 0; i < N-1; ++i)
printf("%s %.2fm %.1fkg\n\n", st[i].name, st[i].h, st[i].w);
printf("%s %.2fm %.1fkg\n", st[N-1].name, st[N-1].h, st[N-1].w);
}
return 0;
}



你可能感兴趣的:(su)