编程语言
首页 > 编程语言> > PTA乙级(1077 互评成绩计算 (20分),(C++取整)

PTA乙级(1077 互评成绩计算 (20分),(C++取整)

作者:互联网

C++取整

头文件:#include <cmath>

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 int main()
 5 {
 6     double a=2.5;
 7     cout<<ceil(a)<<endl;   //向上取整
 8     cout<<floor(a)<<endl;   //向下取整
 9     cout<<round(a)<<endl;   //四舍五入
10     //不使用函数实现
11     //向下取整
12     cout<<(int)a<<endl;
13     //向上取整
14     cout<<(a>(int)a?(int)a+1:(int)a)<<endl;
15     //四舍五入
16     cout<<(int)(a+0.5)<<endl;
17     return 0;
18 }

 

1077 互评成绩计算 (20分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805262303477760

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <iostream>
 7 #include <cstdlib>
 8 using namespace std;
 9 int main()
10 {
11     int n,m,temp;
12     int g1,g2;
13     int max,min;
14     int i,j,k;
15     cin>>n>>m;
16     for(i=0;i<n;i++)
17     {
18         cin>>g2;
19         vector<int> v;
20         int sum=0;
21         for(j=0;j<n-1;j++)
22         {
23             cin>>temp;
24             if(temp>=0&&temp<=m) v.push_back(temp);
25         }
26         sort(v.begin(),v.end());
27         for(j=1;j<v.size()-1;j++) sum+=v[j];
28 
29         cout<<(int)((sum*1.0/(v.size()-2)+g2)/2+0.5)<<endl;
30     }
31     return 0;
32

标签:20,temp,int,1077,namespace,C++,include
来源: https://www.cnblogs.com/jianqiao123/p/12203793.html