2 solutions

  • 0
    @ 2022-11-26 17:40:51
    #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;
    }
    

    Information

    ID
    6482
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    102
    Accepted
    47
    Uploaded By