2 solutions
-
0
#include<iostream> #include<iomanip> using namespace std; int main(){ int n, x, cnt1 = 0, cnt2 = 0; //总人数,分数,及格人数,优秀人数 float ratio1, ratio2; //及格率, 优秀率 cin >> n; for(int i = 1; i <= n; i++){ cin >> x; if(x >= 60) cnt1++; if(x >= 85) cnt2++; } ratio1 = 1.0 * cnt1/n * 100; //因为cnt1 和 n 都为整数,所以乘以1.0转成浮点数 ratio2 = 1.0 * cnt2/n * 100; cout << setprecision(0) << fixed << ratio1 << "%\n"<<ratio2 << "%\n" << endl; //四舍五入,保留整数 return 0; }
-
0
//stl:int round(double x) ----->四舍五入函数 #include<bits/stdc++.h> using namespace std; int n,a,b,x; int main(){ //freopen("t.in","r",stdin); //freopen("t.out","w",stdout); cin>>n; int tmp=n; while(tmp--){ cin>>x; if(x>=60)b++; if(x>=85)a++; } double ans1=(double)b/n*100; double ans2=(double)a/n*100; cout<<round(ans1)<<"%"<<endl; cout<<round(ans2)<<"%"; return 0; }
- 1
Information
- ID
- 6482
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 102
- Accepted
- 47
- Uploaded By