dsbanana 2015-05-30 13:52 采纳率: 0%
浏览 4096

c++程序运行时出现deque iterator not dereferencable

我在做一个c++的二十四点游戏,现在只是在做1~9的运算,代码如下:
#include
#include
#include
#include
using namespace std;
unsigned int i;
int main()
{
stack n1;
stack n2;
stack n3;
int m;
void houzhui(string,stack &, stack &);
int calculate(stack &, stack &);
srand((unsigned)time(NULL));
cout << rand() % 9 + 1 << " " << rand() % 9 + 1 << " " << rand() % 9 + 1 << " " << rand() % 9 + 1 << endl;
string shizi;
cin >> shizi;
houzhui(shizi, n1, n2);
m = calculate(n1, n3);
if (m != -1)
{
if (n3.top() == 24)
cout << "结果正确" << endl;
else
cout << "结果错误" << endl;
}
else
cout << "计算过程中除数出现0!" << endl;
system("pause");
}
void houzhui(string shizi, stack &n1, stack &n2)
{
int check(char);
for (i = 0; i < shizi.size(); i++)
{
if (shizi[i] >= '1' && shizi[i] <= '9')
n1.push(shizi[i]);
else
{
if (n2.empty())
n2.push(shizi[i]);
else
{
if (shizi[i] == ')')
{
while (n2.top() != '(')
{
n1.push(n2.top());
n2.pop();
}
n2.pop();
}
if (check(shizi[i]) < check(n2.top()))
{
if (n2.top() != '(')
{
do
{
n1.push(n2.top());
n2.pop();
if (n2.empty())
break;
} while (check(shizi[i]) <= check(n2.top()));
n2.push(shizi[i]);
}
n2.push(shizi[i]);
}
else
n2.push(shizi[i]);
}
}
}
while (!n2.empty())
{
n1.push(n2.top());
n2.pop();
}
}
int calculate(stack &n1, stack &n3)
{
char c[100];
double s1, s2, s;
c[n1.size()] = '\0';
for (i = n1.size() - 1; i >= 0; i--)
{
c[i] = n1.top();
n1.pop();
}
for (i = 0; c[i]!='\0'; i++)
{
if (c[i] >= '1'&&c[i] <= '9')
n3.push(c[i]-'0');
else
{
if (c[i] != '/')
{
switch (c[i])
{
case '+':s2 = n3.top(); n3.pop(); s1 = n3.top(); n3.pop(); s = s1 + s2; n3.push(s); break;
case '-':s2 = n3.top(); n3.pop(); s1 = n3.top(); n3.pop(); s = s1 - s2; n3.push(s); break;
case '*':s2 = n3.top(); n3.pop(); s1 = n3.top(); n3.pop(); s = s1*s2; n3.push(s); break;
}
}
else
{
s2 = n3.top();
if (s2 != 0)
{
n3.pop();
s1 = n3.top();
n3.pop();
s = s1 / s2;
n3.push(s);
}
else
return -1;
}
}
}
return 0;
}
int check(char c)
{
if (c == '(' || c == ')')
return 1;
if (c == '*' || c == '/')
return 0;
if (c == '+' || c == '-')
return -1;
return -1;
}
为何运行时出现错误deque iterator not dereferencable的?纠结了好多天,还有如果要添加上10~13的运算,要怎么做?多位数的后缀表达式怎么运算?

  • 写回答

2条回答 默认 最新

  • dsbanana 2015-05-30 13:55
    关注

    #include
    #include
    #include
    #include
    明明是这个,发出来却是这样:
    #include
    #include
    #include
    #include
    搞什么鬼啊

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。