参考:https://blog.csdn.net/sinat_28199083/article/details/79619774
题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805262303477760
关键在于获取数据!
#include<iostream> #include<climits> #include<cmath> #include<sstream> using namespace std; int main() { int n; cin >> n; int legal = 0; cin >> legal; while(n--) { double ans = 0; cin >> ans; int scores = 0; double sum = 0; double legalTimes = 0; int mins = INT_MAX, maxs = INT_MIN; string numbers; // 获取一行数字+空格的字符串 getline(cin, numbers); // 初始化字符串流 stringstream ss(numbers); // 将字符串流输入给scores(类似cin) while(ss >> scores) { if(scores >= 0 && scores <= legal) { legalTimes++; sum += scores; maxs = max(maxs, scores); mins = min(mins, scores); } } legalTimes -= 2; sum -= maxs; sum -= mins; sum /= legalTimes; ans += sum; ans /= 2; cout << round(ans) << endl; } return 0; }