完成程序《大奖赛评分B》-代码:

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void print_arr(int arr[],int num)
{
	for (int j = 0; j < num; j++)
	{
		printf("%d ", arr[j]);
	}
	printf("\n");
}

int cmp_int(const void* e1, const void* e2)
{
	return *(int*)e1 - *(int*)e2;
}

int main()
{
	char str[200] = { 0 };
	int arr[50] = { 0 };
	float num = 0;
	int sum = 0;

	gets(str);

	int i, j = 0, k = 0;

	for (i = 0; str[i] != '-'; i++) 
	{
		if (str[i] >= '0' && str[i] <= '9') 
		{
			arr[j] = arr[j] * 10 + (str[i] - '0');
		}
		else if (str[i] == ' ' && k < 50) 
		{
			j++;
			k++;
		}
	}

	qsort(arr, 50, sizeof(int), cmp_int);

	int u = 0;
	for (int j = 0; j < 50; j++)
	{
		if (arr[j] != 0)
		{
			if (u > 1 && j < 48)
			{
				sum += arr[j];
				num++;
			}
			u++;
		}
	}

	float average = (float)sum / num;
	printf("%.2f\n", average);
	return 0;
}



上一篇:雷池社区版7.1新版本自定义NGINX配置分析


下一篇:【Unity】Unity拖拽在Android设备有延迟和卡顿问题的解决-三、解决方案