2021-02-26

CCF-CSP\专题\题型A 简单模拟\201903-2 二十四点

简单的中缀表达式计算,无括号,数字是0-9的数字,加减乘除四则运算。
注意不需要先转后缀再计算,直接遍历(带栈)就可以计算了。

#include <cstdio>
#include <stack>
using namespace std;

int N;

const int Len=7;

int Ord(char c) {
	switch (c) {
		case '-':
		case '+':
			return 1;
		case 'x':
		case '/':
			return 2;
		default:
			return 0;
	}
}

int Compute2(stack<int>& data, char op) {
	int b=data.top(); data.pop();
	int a=data.top(); data.pop();
	switch (op) {
		case '+':
			a+=b;
			break;
		case '-':
			a-=b;
			break;
		case 'x':
			a*=b;
			break;
		case '/':
			a/=b;
			break;
	}
	data.push(a);
}

/*
计算不带括号,单个字符的中缀表达式。
1. 需要两个栈(必须);
2. 涉及switch语句,注意break不要漏了。 
*/ 
int Compute(char str[], int len) {
	stack<char> s;
	stack<int> data;
	
	for (int i=0;i<len;++i) {
		char c=str[i];
		if (!Ord(c)) {
			// 运算数。 
			data.push(c-'0');
		} else {
			while (!s.empty() && Ord(s.top()) >= Ord(c)) {
				char op=s.top();
				s.pop();
				Compute2(data, op);
			}
			s.push(c);
		}
	}
	while (!s.empty()) {
		char op=s.top();
		s.pop();
		Compute2(data, op);
	}
	return data.top();
}

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	scanf("%d", &N);
	while (N--) {
		char str[10];
		scanf("%s", str);
		int ans=Compute(str, Len);
		puts(ans==24?"Yes":"No");
	}
	return 0;
}

2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
最新发布
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值