写的不好,见谅!
参考代码:
#include <iostream> #include <algorithm> using namespace std; bool cmp(int a,int b) { return a>b; } int main() { int a=0,b=0,c=0,d=0,e=0,n,s[1005]; cin>>n; for(int i=0;i<n;i++){ cin>>s[i]; if(90<=s[i]&&s[i]<=100)a++; else if(80<=s[i]&&s[i]<=89)b++; else if(70<=s[i]&&s[i]<=79)c++; else if(60<=s[i]&&s[i]<=69)d++; else e++; } sort(s,s+n,cmp); cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl; int max=a; if(max<b)max=b; if(max<c)max=c; if(max<d)max=d; if(max<e)max=e; cout<<max<<endl; if(max==a){ for(int i=0;i<n;i++){ if(90<=s[i]&&s[i]<=100) cout<<s[i]<<" "; } cout<<endl; } if(max==b){ for(int i=0;i<n;i++){ if(80<=s[i]&&s[i]<=89) cout<<s[i]<<" "; } cout<<endl; } if(max==c){ for(int i=0;i<n;i++){ if(70<=s[i]&&s[i]<=79) cout<<s[i]<<" "; } cout<<endl; } if(max==d){ for(int i=0;i<n;i++){ if(60<=s[i]&&s[i]<=69) cout<<s[i]<<" "; } cout<<endl; } if(max==e){ for(int i=0;i<n;i++){ if(0<=s[i]&&s[i]<=59) cout<<s[i]<<" "; } cout<<endl; } return 0; }
0.0分
0 人评分
十->二进制转换 (C++代码)(零和负数需要特殊处理)浏览:1135 |
陶陶摘苹果 (C语言代码)浏览:1652 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1273 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:747 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:729 |
大神老白 (C语言代码)浏览:691 |
WU-小九九 (C++代码)浏览:1713 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:582 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:583 |
sizeof的大作用 (C语言代码)浏览:1591 |