原题链接
2871. 成绩统计 - AcWing题库https://www.acwing.com/problem/content/description/2874/
除法实现四舍五入:C语言实现四舍五入_Spf小鱼干-CSDN博客_c语言四舍五入https://blog.csdn.net/weixin_38505045/article/details/79994536
#include<iostream>
using namespace std;
const int N = 10010;
int main()
{
int n;cin>>n;
float jige=0.0,youxiu=0.0;//人数
for(int i =0;i<n;i++)
{
int g;cin>>g;
if(g>=85)
{
jige++;
youxiu++;
}
else if(g>=60)
jige++;
}
float j1 = jige/n*100;
int j2 = j1;
if((j1-j2)>=0.5)
cout<<(j2+1)<<"% ";
else
cout<<j2<<"% ";
float y1 = youxiu/n*100;
int y2 = y1;
if((y1-y2)>=0.5)
cout<<(y2+1)<<"%";
else
cout<<y2<<"%";
return 0;
}
#include<iostream>
using namespace std;
int main(){
int T;
int sum_85 = 0, sum_60 = 0;
cin >> T;
int n = T;
while(T--){
int score;
cin>>score;
if(score >= 85) sum_85 ++;
if(score >= 60) sum_60 ++;
}
printf("%d%%\n%d%%", int(float(sum_60) * 100 / n + 0.5), int(float(sum_85) * 100 / n + 0.5));
return 0;
}
————————————————
版权声明:本文为CSDN博主「和BUG做朋友的ZORO」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_45914759/article/details/114103305