54分求调
查看原帖
54分求调
1494443
wdmzjhyk楼主2024/12/17 13:59
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include<algorithm>
struct shijian
{
	int sign;
	int time;
};
bool compare(const struct shijian &a, const struct shijian &b)
{
	return a.time < b.time;
}
int main() 
{
	int n;
	scanf("%d", &n);
	struct shijian* a = (struct shijian*)malloc(n * sizeof(struct shijian));
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i].time);
		a[i].sign = i;
	}
	std::sort(a, a + n, compare);
	float sum = 0.0,sum2=0.0;
	for (int k = 0; k < n-1; k++)
	{
		sum += a[k].time;
		sum2 += sum;
	}
	float ave = sum2 / n;
	for (int j = 0; j < n; j++)
	{
		printf("%d ", a[j].sign+1);
	}
	printf("\n");
	printf("%.2f", ave);
	free(a);
	return 0; 
}
2024/12/17 13:59
加载中...