CSP练习1:201903-1小中大

题目:

 本题算法思想比较简单,但是要注意的是在进行中位数求解的时候一定要注意对于其正负的判断,由于是采用0.5调节大小的方式,当为正则+0.5为-则减0.5,在为0时,要注意进行判断到底为正还是负。

#include <stdio.h>
#include <math.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	int shuzi[100010];
	int i = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &shuzi[i]);
	}
	int result[3];//用来存放结果

	if (shuzi[0] >= shuzi[n - 1])
	{
		result[0] = shuzi[0];
		result[2] = shuzi[n - 1];
	}
	else
	{
		result[0] = shuzi[n - 1];
		result[2] = shuzi[0];
	}
	if (n % 2 == 1)
	{

		result[1] = shuzi[n / 2];
		printf("%d %d %d", result[0], result[1], result[2]);
	}
	else
	{


		n = n / 2;
		if ((shuzi[n] + shuzi[n - 1]) % 2 == 0)
		{
			result[1] = (shuzi[n] + shuzi[n - 1]) / 2;
			printf("%d %d %d", result[0], (int)result[1], result[2]);
		}
		else
		{
			int d = (shuzi[n] + shuzi[n - 1]) / 2;
			double t = 0;
			if (d > 0)
			{
				t = d + 0.5;
			}
			else if (d<0)
			{
				t = d - 0.5;
			}
			else
			{//这里是当时自己写程序是没有注意到的
				if (((shuzi[n] + shuzi[n - 1])*1.0 / 2)>0)
				{
					t = 0.5;
				}
				else
				{
					t = -0.5;
				}
			}
			printf("%d %.1f %d", result[0], t, result[2]);


		}

	}


	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值