1 条题解
-
0
C++ :
#include <bits/stdc++.h> using namespace std; int main(){ int arr[1000],n,i,a = 0,b = 0,c = 0,d = 0; cin>>n; for(i = 0;i < n;i++){ cin>>arr[i]; if(arr[i] <= 18){ a++; }else if(arr[i] <= 35){ b++; }else if(arr[i] <= 60){ c++; }else{ d++; } } cout<<a<<" "<<fixed<<setprecision(2)<<a*100.0/n<<"%"<<endl; cout<<b<<" "<<fixed<<setprecision(2)<<b*100.0/n<<"%"<<endl; cout<<c<<" "<<fixed<<setprecision(2)<<c*100.0/n<<"%"<<endl; cout<<d<<" "<<fixed<<setprecision(2)<<d*100.0/n<<"%"<<endl; }
Python :
n=int(input()) s1=list(map(int,input().split())) alen=len([item for item in s1 if 0<=item<=18]) print("%d %.2lf%%"%(alen,100*alen/len(s1))) alen=len([item for item in s1 if 19<=item<=35]) print("%d %.2lf%%"%(alen,100*alen/len(s1))) alen=len([item for item in s1 if 36<=item<=60]) print("%d %.2lf%%"%(alen,100*alen/len(s1))) alen=len([item for item in s1 if 61<=item]) print("%d %.2lf%%"%(alen,100*alen/len(s1)))
- 1
信息
- ID
- 2346
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者