CCF 201903-1 小中大

 

试题编号:201903-1
试题名称:小中大
时间限制:1.0s
内存限制:512.0MB
问题描述:


      这道题初看起来没什么好说的,简单的送分题,但是做出来发现只能得90分,多次修改未能解决,看大佬程序才发现是输出的设置上有问题。题目要求中位数若是整数则输出整数,若是分数则输出四舍五入后保留一位小数。看题时想的是小数只可能是.5,那么将和/2.0将数据转换为浮点型输出即可,但是当输出为整数时,仍按小数输出,就会报错,需要判断一下,是整数就用(int)强制转换一下即可,最后时100分,程序如下:

#include <map>  
#include <cmath>  
#include <queue>  
#include <cstdio>  
#include <string>  
#include <cstring>  
#include <iostream>  
#include <algorithm> 
#include <sstream> 
#include <time.h> 
#include <vector>
#include <list>
#include <iostream>
#include<iomanip>

using namespace std;

int main()
{
	int i, j, N, M;
	cin >> N;
	vector<long> data(N);
	int result[4],save;
	for (int i = 0; i < N; i++)
	{
		cin >> save;
		if (N % 2 == 1)
		{
			if (i == 0)
				result[0] = save;
			else if(i == N / 2)
				result[1] = save;
			else if(i == N  - 1)
				result[3] = save;
		}
		else
		{
			if (i == 0)
				result[0] = save;
			else if (i == N / 2 -1)
				result[1] = save;
			else if (i == N / 2)
				result[2] = save;
			else if (i == N - 1)
				result[3] = save;
		}
	}
	if (result[0] < result[3])
	{
		if (N % 2 == 1)
			cout << result[3] << ' ' << result[1] << ' ' << result[0] << endl;
		else
		{
			float out = (result[1] + result[2]) / 2.0;
			if (out == (int)out)
				cout << result[3] << ' ' << (int)out << ' ' << result[0] << endl;
			else
				cout << result[3] << ' ' << out << ' ' << result[0] << endl;
		}
	}
	else
	{
		if (N % 2 == 1)
			cout << result[0] << ' ' << result[1] << ' ' << result[3] << endl;
		else
		{
			float out = (result[1] + result[2]) / 2.0;
			if (out == (int)out)
				cout << result[0] << ' ' << (int)out << ' ' << result[3] << endl;
			else
				cout << result[0] << ' ' << out << ' ' << result[3] << endl;
		}
	}
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值