#include <stdio.h>
#define SIZE 10
double stack[SIZE];
int sp;
void push(double value);
double pop(void);
int isFull(void);
int isEmpty(void);
void answer(void);
void reset(void);
int flag=0;
int main(void)
{ reset();
while (1)
{ int resp;
double data;
if (resp==0) break;
switch (resp)
{ case 1:
if (isEmpty
()) { printf("エラー: スタックが空です。\n");} else { double b=pop();
if (isEmpty
()) { printf("エラー: スタックに値が不足しています。\n"); push
(b
); } else { double a=pop(); push(a+b); } } break;
case 2: if (isEmpty
()) { printf("エラー: スタックが空です。\n");} else { double b=pop();
if (isEmpty
()) { printf("エラー: スタックに値が不足しています。\n"); push
(b
); } else { double a=pop(); push(a-b); } } break;
case 3:
if (isEmpty
()) { printf("エラー: スタックが空です。\n"); } else { double b=pop();
if (isEmpty
()) { printf("エラー: スタックに値が不足しています。\n"); push
(b
); } else { double a=pop(); push(a*b); } } break;
case 4:
if (isEmpty
()) { printf("エラー: スタックが空です。\n"); } else { double b=pop();
if (isEmpty
()) { printf("エラー: スタックに値が不足しています。\n"); push
(b
); } else { double a=pop();
if (b
==0) { printf("エラー。\n"); push
(a
); push
(b
); } else { push(a/b); } } } break;
case 5:
push(data);
break;
case 9:
answer();
flag=1;
break; }
if(flag==1) break; }
return 0;}
void push(double value)
{ if (isFull
()) { printf("スタックが満杯で入りませんでした。\n"); } else { stack[sp++]=value; } }
double pop(void)
{ if (isEmpty())
{ printf("スタックが空で取り出せませんでした。\n"); return 0; } else { return stack[--sp]; } }
int isFull(void)
{ if(sp>=SIZE) { return 1;}
else { return 0; } }
int isEmpty(void)
{ if(sp<=0) { return 1; }
else { return 0; }}
void answer(void)
{ if (isEmpty())
else { printf("計算結果:%lf",pop
()); } }
void reset(void)
{ sp=0; }
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgU0laRSAxMApkb3VibGUgc3RhY2tbU0laRV07CmludCBzcDsKdm9pZCBwdXNoKGRvdWJsZSB2YWx1ZSk7IApkb3VibGUgcG9wKHZvaWQpOyAgCmludCBpc0Z1bGwodm9pZCk7IAppbnQgaXNFbXB0eSh2b2lkKTsgCnZvaWQgYW5zd2VyKHZvaWQpOyAKdm9pZCByZXNldCh2b2lkKTsgCmludCBmbGFnPTA7CmludCBtYWluKHZvaWQpCnsgICByZXNldCgpOwogICAgd2hpbGUgKDEpIAogICAgeyBpbnQgcmVzcDsKICAgICBkb3VibGUgZGF0YTsKICAgICBzY2FuZigiJWQiLCZyZXNwKTsKCiAgICAgIGlmIChyZXNwPT0wKSBicmVhazsKICAgICAgc3dpdGNoIChyZXNwKQogICAgICB7ICBjYXNlIDE6CiAgICAgICAgaWYgKGlzRW1wdHkoKSkgeyBwcmludGYoIuOCqOODqeODvDog44K544K/44OD44Kv44GM56m644Gn44GZ44CCXG4iKTt9CiAgICAgICAgZWxzZSB7IGRvdWJsZSBiPXBvcCgpOwogICAgICAgIGlmIChpc0VtcHR5KCkpIHsgcHJpbnRmKCLjgqjjg6njg7w6IOOCueOCv+ODg+OCr+OBq+WApOOBjOS4jei2s+OBl+OBpuOBhOOBvuOBmeOAglxuIik7IHB1c2goYik7IH0KICAgICAgICBlbHNlIHsgZG91YmxlIGE9cG9wKCk7ICBwdXNoKGErYik7IH0gfSBicmVhazsKCiAgICAgICAgY2FzZSAyOiAgaWYgKGlzRW1wdHkoKSkgeyBwcmludGYoIuOCqOODqeODvDog44K544K/44OD44Kv44GM56m644Gn44GZ44CCXG4iKTt9CiAgICAgICAgICAgZWxzZSB7IGRvdWJsZSBiPXBvcCgpOwogICAgICAgICAgIGlmIChpc0VtcHR5KCkpIHsgcHJpbnRmKCLjgqjjg6njg7w6IOOCueOCv+ODg+OCr+OBq+WApOOBjOS4jei2s+OBl+OBpuOBhOOBvuOBmeOAglxuIik7IHB1c2goYik7IH0KICAgICAgICAgICAgIGVsc2UgeyBkb3VibGUgYT1wb3AoKTsgcHVzaChhLWIpOyB9IH0gICBicmVhazsKCiAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgIGlmIChpc0VtcHR5KCkpIHsgIHByaW50Zigi44Ko44Op44O8OiDjgrnjgr/jg4Pjgq/jgYznqbrjgafjgZnjgIJcbiIpOyB9IAogICAgICAgICAgICAgICAgZWxzZSB7ICBkb3VibGUgYj1wb3AoKTsKICAgICAgICAgICAgICAgIGlmIChpc0VtcHR5KCkpIHsgcHJpbnRmKCLjgqjjg6njg7w6IOOCueOCv+ODg+OCr+OBq+WApOOBjOS4jei2s+OBl+OBpuOBhOOBvuOBmeOAglxuIik7IHB1c2goYik7IH0KICAgICAgICAgICAgICAgICBlbHNlIHsgZG91YmxlIGE9cG9wKCk7ICBwdXNoKGEqYik7IH0gfSAgYnJlYWs7CgogICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICBpZiAoaXNFbXB0eSgpKSB7IHByaW50Zigi44Ko44Op44O8OiDjgrnjgr/jg4Pjgq/jgYznqbrjgafjgZnjgIJcbiIpOyB9CiAgICAgICAgICAgICAgICBlbHNlIHsgZG91YmxlIGI9cG9wKCk7CiAgICAgICAgICAgICAgICBpZiAoaXNFbXB0eSgpKSB7IHByaW50Zigi44Ko44Op44O8OiDjgrnjgr/jg4Pjgq/jgavlgKTjgYzkuI3otrPjgZfjgabjgYTjgb7jgZnjgIJcbiIpOyAgcHVzaChiKTsgfQogICAgICAgICAgICAgICAgZWxzZSB7ICBkb3VibGUgYT1wb3AoKTsKICAgICAgICAgICAgICAgIGlmIChiPT0wKSB7ICBwcmludGYoIuOCqOODqeODvOOAglxuIik7ICBwdXNoKGEpOyAgcHVzaChiKTsgfQogICAgICAgICAgICAgICAgZWxzZSB7IHB1c2goYS9iKTsgfSB9IH0gICBicmVhazsKCiAgICAgICAgICAgIGNhc2UgNToKICAgICAgICAgICAgcHJpbnRmKCJwdXNoOiIpOwogICAgICAgICAgICBzY2FuZigiJWxmIiwmZGF0YSk7CiAgICAgICAgICAgIHByaW50ZigiJWxmXG4iLGRhdGEpOwogICAgICAgICAgICBwdXNoKGRhdGEpOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgCiAgICAgICAgICAgIGNhc2UgOToKICAgICAgICAgICAgICAgIGFuc3dlcigpOwogICAgICAgICAgICAgICAgZmxhZz0xOwogICAgICAgICAgICAgICAgYnJlYWs7IH0KICAgICAgICAgICAgICAgIGlmKGZsYWc9PTEpIGJyZWFrOyB9CiAgICAgICAgICAgICAgICByZXR1cm4gMDt9Cgp2b2lkIHB1c2goZG91YmxlIHZhbHVlKSAKeyAgaWYgKGlzRnVsbCgpKSB7IHByaW50Zigi44K544K/44OD44Kv44GM5rqA5p2v44Gn5YWl44KK44G+44Gb44KT44Gn44GX44Gf44CCXG4iKTsgfQogICBlbHNlIHsgIHN0YWNrW3NwKytdPXZhbHVlOyB9IH0KCmRvdWJsZSBwb3Aodm9pZCkgCnsgIGlmIChpc0VtcHR5KCkpCnsgICBwcmludGYoIuOCueOCv+ODg+OCr+OBjOepuuOBp+WPluOCiuWHuuOBm+OBvuOBm+OCk+OBp+OBl+OBn+OAglxuIik7IHJldHVybiAwOyB9CiBlbHNlIHsgIHJldHVybiBzdGFja1stLXNwXTsgfSB9CiAgCmludCBpc0Z1bGwodm9pZCkgCnsgaWYoc3A+PVNJWkUpICB7IHJldHVybiAxO30KZWxzZSB7IHJldHVybiAwOyB9IH0KCmludCBpc0VtcHR5KHZvaWQpCnsgaWYoc3A8PTApIHsgcmV0dXJuIDE7IH0KZWxzZSB7IHJldHVybiAwOyB9fQoKdm9pZCBhbnN3ZXIodm9pZCkgCnsgIGlmIChpc0VtcHR5KCkpIAp7ICBwcmludGYoIuOCueOCv+ODg+OCr+OBr+epuuOBp+OBmeOAglxuIik7IH0KICAgZWxzZSB7IHByaW50Zigi6KiI566X57WQ5p6cOiVsZiIscG9wKCkpOyB9IH0KICAgCnZvaWQgcmVzZXQodm9pZCkKeyAgc3A9MDsgIH0=