1.小中大
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=100010;
int main(){
int n, iMax, iMin, arr[MAXN];
double iMid;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &arr[i]);
iMax = max(arr[0], arr[n-1]);
iMin = min(arr[0], arr[n-1]);
if(n & 1){
iMid = arr[n/2];
printf("%d %d %d\n",iMax, (int)iMid, iMin);
}
else{
iMid = (arr[n/2-1] + arr[n/2]) * 1.0 / 2;
iMid - (int)iMid == 0 ? printf("%d %d %d\n", iMax, (int)iMid, iMin) : printf("%d %.1f %d\n",iMax, iMid, iMin);
}
return 0;
}
4
0 1 2 3
3 1.5 0
2.二十四点
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int n;
string str;
stack<int> st;
cin >> n;
while (n--){
cin >> str;
while (!st.empty())
st.pop();
for(int i = 0;i < str.length(); i++){
if (isdigit(str[i])){
st.push(str[i] - '0');
}
else if (str[i] == '+'){
continue;
}
else if (str[i] == '-'){
st.push((str[++i] - '0') * -1);
}
else if (str[i] == 'x') {
int x = st.top();
st.pop();
st.push((str[++i] - '0') * x);
}
else if (str[i]