1 条题解
-
0
C++ :
#include <bits/stdc++.h> using namespace std; int a[10000],n,i,j,x,s = 0; int main(){ cin>>n>>x; for(i = 0;i < n;i++){ cin>>a[i]; } sort(a,a+n); for(i = x;i < n - x;i++){ s = s + a[i]; } double v = s * 1.0 / (n - x * 2); cout<<fixed<<setprecision(1)<<v<<endl; }Pascal :
var a:array[1..100000] of longint; b,i,j,t,x:longint; s:real; begin read(b,x); for i:=1 to b do read(a[i]); for i:=1 to b-1 do for j:=i+1 to b do if a[j]<a[i] then begin t:=a[i];a[i]:=a[j];a[j]:=t;end; for i:=1+x to b-x do s:=s+a[i]; s:=s/(b-(2*x)); write(s:0:1); end.Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n,x,s = 0; n = sc.nextInt(); x = sc.nextInt(); int[] a = new int[n]; for(int i = 0;i < n;i++){ a[i] = sc.nextInt(); } int t; for(int i = 1;i <= n - 1;i++){ for(int j = 0;j <= n - i - 1;j++){ if(a[j] > a[j + 1]){ t = a[j]; a[j] = a[j + 1]; a[j + 1] = t; } } } for(int i = x;i <= n - x - 1;i++){ s += a[i]; } double r = s * 1.0 / (n - x - x); System.out.println(String.format("%.1f", r)); } }Python :
s = input().split() # 学生总数 n = int(s[0]) # 取掉的个数x x = int(s[1]) a = input().split() b = [] su = 0 # 列表类型转换 for v in a: b.append(int(v)) # 从小到大排序 b.sort() del b[0:x] del b[-1 * x:] for v in b: su += v av = su / len(b) print('%.1f' % av)
- 1
信息
- ID
- 453
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者