1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 21:58:41 +00:00
202401-programming-assignments/【实践课外】7.数组1/7-14 数组-吹泡泡.c

41 lines
763 B
C
Raw Normal View History

2024-11-06 03:38:23 +00:00
#include <stdio.h>
const double PI = 3.14;
const double FDT = 1.33;
int n, id[1005];
double v[1005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
double r;
scanf("%lf", &r);
v[i] = FDT * PI * r * r * r;
id[i] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= n; j++) {
if (v[j] > v[j - 1] || (v[j] == v[j - 1] && id[j] < id[j - 1])) {
double t = v[j];
v[j] = v[j - 1];
v[j - 1] = t;
int tt = id[j];
id[j] = id[j - 1];
id[j - 1] = tt;
}
}
}
for (int i = 1; i <= n; i++) {
printf("%.2lf %d\n", v[i], id[i]);
}
return 0;
}