CCF认证-201903-2 二十四点提示运行错误。。。求大佬解决
#include<iostream>
#include<stack>
using namespace std;
bool cmp(char top, char out)
{
if ((top == '+' || top == '-') && (out == '+' || out == '-'))
return true;
else if ((top == 'x' || top == '/') && (out == 'x' || out == '/'))
return true;
else if ((top == 'x' || top == '/') && (out == '+' || out == '-'))
return true;
else
return false;
}
int calculate(int nx, int nh, char sign)
{
switch (sign)
{
case '+': return nx + nh;break;
case '-': return nx - nh;break;
case 'x': return nx * nh;break;
case '/': return nx / nh;break;
}
}
char s[8];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
stack<int> num;
stack<char> sym;
while (!num.empty())
num.pop();
while (!sym.empty())
sym.pop();
for (int j = 0; j < 8; j++)
{
scanf("%c", &s[j]);
if (s[j] != '\n')
{
if (s[j] >= '0' && s[j] <= '9')
num.push(s[j] - '0');
else if (sym.empty())
{
sym.push(s[j]);
}
else
{
if (cmp(sym.top(), s[j]))
{
while (cmp(sym.top(), s[j]))
{
int nh = num.top();
num.pop();
int nx = num.top();
num.pop();
num.push(calculate(nx, nh, sym.top()));
sym.pop();
}
sym.push(s[j]);
}
else
sym.push(s[j]);
}
}
}
while (!sym.empty())
{
int nh = num.top();
num.pop();
int nx = num.top();
num.pop();
num.push(calculate(nx, nh, sym.top()));
sym.pop();
}
if (num.top() == 24)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
...全文
相关推荐
ccf认证
整理2013-2019年ccf 认证python源代码,都是满分的,希望对要考此认证的有帮助(只有每期的前两道)
ccf软件能力认证上机考试指导书
关于ccf上机考试的一些指导说明【含注意事项和实例说明】
CCF-CSP认证前两题答案(初始-2018).rar
用C++或C写的CCF-CSP认证前两题,CCF-CSP认证前两题答案(初始-2018),多次测试+二刷
ccf-201609-2-火车购票
ccf认证考试2016年09月考试的第二题,火车购票ac代码--------
2019 CCF非专业级别软件能力认证第一轮 (CSP-J)入门级答案及解析.rar
适合参加csp、noip普及组初赛的同学


