小中大
#include<bits/stdc++.h>
using namespace std;
int a[100010];
const int inf=0x3f3f3f3f;
int main()
{
int n;cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
printf("%d ",a[n]);
if(n%2==0)
{
if((a[n/2]+a[n/2+1])%2==1)
{
printf("%.1f ",(a[n/2]+a[n/2+1])/2.0);
}else{
printf("%d ",(a[n/2]+a[n/2+1])/2);
}
}else{
printf("%d ",(a[n/2+1]));
}
printf("%d
",a[1]);
}
二十四点
(http://118.190.20.162/view.page?gpid=T88)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
while(n--)
{
string s;cin>>s;
stack<int>q;
stack<char>op;
for(int i=0;i<s.size();i++)
{
if(isdigit(s[i])) q.push(s[i]-'0');
else if(s[i]=='-') {
q.push(-1*(s[i+1]-'0'));
op.push('+');
i++;
}
else if(s[i]=='/')
{
int top=q.top();q.pop();
q.push(top/(s[i+1]-'0'));
i++;
}
else if(s[i]=='x'){
int top=q.top();q.pop();
q.push(top*(s[i+1]-'0'));
i++;
}
else op.push(s[i]);
}
// while(!op.empty())
// {
// cout<<op.top()<<" ";op.pop();
// }
while(q.size()>1)
{
int x=q.top();q.pop();
int y=q.top();q.pop();
if(op.top()=='+') q.push(x+y);
if(op.top()=='x') q.push(x*y);
if(op.top()=='/') q.push(y/x);
// printf("%d%c%d=%d
",y,op.top(),x,q.top());
op.pop();
}
if(q.top()==24)
{
puts("Yes");
}else{
puts("No");
}
}
}
/*
10
9+3+4x3
5+4x5x5
7-9-9+8
5x6/5x4
3+5+7+9
1x1+9-9
1x9-5/9
8/5+6x9
6x7-3x6
6x4+4/5
*/