1077 互评成绩计算 setprecision有误差

易错点

  1. 很多关键细节在题干背景里,而不单单是输出格式里,很容易忽略
  2. setprecision有误差,.5会舍去而不是进位

代码

#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;

int main()
{
	int n,m;
	int p;
	float tmp1,tmp2,tmp3;
	int tmp4;
	int max,min;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		tmp1=0;
		tmp2=0;
		tmp4=0;
		max=-1;
		min=m+1;
		for(int j=0;j<n;j++){
			if(j==0){
				cin>>p;
				tmp1=p;
			}
			else{
				cin>>p;
				if(p>=0&&p<=m){
					if(max<p){
						max=p;
					}
					if(min>p){
						min=p;
					}
					tmp2+=p;
					tmp4++;
				}
				else{
					
				}
			}
		}
		tmp2=tmp2-max-min;
		tmp2=tmp2/(tmp4-2);
		tmp3=(tmp1+tmp2)/2;
		if((tmp3-int(tmp3))==0.5){
			tmp3+=0.1;
		}
		cout<<fixed<<setprecision(0)<<tmp3<<endl;
	}
	
	return 0;
}
posted @ 2022-07-12 20:27  qwasdasd  阅读(23)  评论(0)    收藏  举报