解题思路:
使用5个数组记录5个分数段,使用五个整形记录五个分数段人数
参考代码:
#include<bits/stdc++.h> using namespace std; int main(){ int a, b, c, d, e; int n; cin >> n; a = b = c = d = e = 0; int A[101] = {0}; int B[90] = {0}; int C[80] = {0}; int D[70] = {0}; int E[60] = {0}; while( n--){ int score; cin >> score; if( score > 89){ A[score]++; a++; }else if( score > 79){ B[score]++; b++; }else if( score > 69){ C[score]++; c++; }else if( score > 59){ D[score]++; d++; }else{ E[score]++; e++; } } int most = a; //记录人数最多的分数段 if(most < b) most = b; if( most < c) most = c; if( most < d) most = d; if( most < e) most = e; cout << a << " " << b << " " << c << " " << d << " " << e << endl << most << endl; int i; if( most == a){ for( i = 100; i > 89; i--){ while( A[i]--) //同分数段不止有一人时继续输出 cout << i << " "; } }else if( most == b){ for( i = 89; i > 79; i--){ while( B[i]--) cout << i << " "; } }else if( most == c){ for( i = 79; i > 69; i--){ while( C[i]--) cout << i << " "; } }else if( most == d){ for( i = 69; i > 59; i--){ while( D[i]--) cout << i << " "; } }else if( most == e){ for( i = 59; i > -1; i--){ while( E[i]--) cout << i << " "; } } return 0; }
0.0分
4 人评分
【数组的距离】 (C语言代码)浏览:787 |
C语言训练-排序问题<1> (C语言代码)浏览:636 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:790 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:611 |
【亲和数】 (C语言代码)浏览:541 |
WU-字符串比较 (C++代码)浏览:824 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:672 |
C语言训练-自由落体问题 (C语言代码)浏览:650 |
勾股数 (C语言代码)浏览:830 |
复数求和 (C语言代码)浏览:995 |