CCF题

201903-01大中小

#include <iostream>
using namespace std;

int main(){
	int n;
	cin>>n;
	int a,b,c;
	int num[n];
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	
	if(num[0]>num[n-1]){
		a=num[0];
		c=num[n-1];
	}else{
		a=num[n-1];
		c=num[0];
	}
	
	if(n%2==0){
		b=(num[n/2-1]+num[n/2])/2;
	}else{
		b=num[n/2];
	}
	
	cout<<a<<' '<<b<<' '<<c;
	return 0;
} 

201903-02 24点

#include <iostream>
#include <stack>

using namespace std;

int main(){
	
	int n;
	cin>>n;
	
	stack<int> num;
	stack<char> sign;
	
	int num1,num2,sum;
	int judge[n]; 
	
	for(int i=0; i<n; i++){
		fflush(stdin);//清空缓存 
		char str[7];
		gets(str);
		
		for(int k=0; k<7; k++){
			if((str[k]-'0'>=0)&&(str[k]-'9'<=9)){
				num.push(str[k]-'0');
			}else if(str[k] == 'x'){
				num1 = num.top();
				num.pop();
				sum = num1*(str[k+1]-'0');
				num.push(sum);
				k+=1;
			}else if(str[k] == '/'){
				num1 = num.top();
				num.pop();
				sum = num1/(str[k+1]-'0');
				num.push(sum);
				k+=1;
			}else{
				sign.push(str[k]);
			}	
		}
		
		if(sign.empty()){
			if(num.top() == 24){
				judge[i]=1;
			}else{
				judge[i]=0;
			}
		}else{
			while(!sign.empty()){
				if(sign.top() == '+'){
					num1 = num.top();
					num.pop();
					num2 = num.top();
					num.pop();
					sign.pop();
					sum = num2 + num1;
					num.push(sum);
				}else{
					num1 = num.top();
					num.pop();
					num2 = num.top();
					num.pop();
					sign.pop();
					sum = num2 - num1;
					num.push(sum);
				}
			}
			
			if(num.top() == 24){
				judge[i]=1;
			}else{
				judge[i]=0;
			}
		}
	}
	
	for(int i=0; i<n; i++){
		if(judge[i]==1){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值