#include<stdio.h>
#define SIZE 5
double stack[SIZE];
int sp;
double pop(void);
void push(double value);
int isFull(void);
int isEmpty(void);
void display(void);
void initialize(void);
int main(void)
{
sp = 0;
int resp, data;
double a,b;
while(1){
printf("1:+ 2:- 3:* 4:/ 5:data input 0:end 9:display ");
if(resp == 9) break;
switch(resp){
case 1: //足し算
a = pop();
b = pop();
push(a + b);
break;
case 2: //引き算
a = pop();
b = pop();
push(a - b);
break;
case 3: //掛け算
a = pop();
b = pop();
push(a * b);
break;
case 4: //割り算
a = pop();
b = pop();
push(a / b);
break;
case 5:
push(data);
break;
}
}
display();
return 0;
}
void initialize(void){
sp = 0;
}
void display(void){
for(int i=0; i<sp; i++){
printf("answer:%lf\n",stack
[i
]); }
}
int isFull(void){
if(sp >= SIZE){
return 1;
}else{
return 0;
}
}
int isEmpty(void){
if(sp <= 0){
return 1;
}else{
return 0;
}
}
void push(double value)
{
if(isFull()){
}else{
stack[sp++] = value;
}
}
double pop(void)
{
if(isEmpty()){
printf("スタックが空で取り出せませんでした\n"); return 0;
}else{
return stack[--sp];
}
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmRvdWJsZSBzdGFja1tTSVpFXTsKaW50IHNwOwpkb3VibGUgcG9wKHZvaWQpOwp2b2lkIHB1c2goZG91YmxlIHZhbHVlKTsKCmludCBpc0Z1bGwodm9pZCk7CmludCBpc0VtcHR5KHZvaWQpOwp2b2lkIGRpc3BsYXkodm9pZCk7CnZvaWQgaW5pdGlhbGl6ZSh2b2lkKTsKaW50IG1haW4odm9pZCkKewogICAgc3AgPSAwOwogICAgaW50IHJlc3AsIGRhdGE7Cglkb3VibGUgYSxiOwogICAgd2hpbGUoMSl7CiAgICAgICAgcHJpbnRmKCIxOisgIDI6LSAzOiogNDovIDU6ZGF0YSBpbnB1dCAgMDplbmQgOTpkaXNwbGF5ICIpOwogICAgICAgIHNjYW5mKCIlZCIsICZyZXNwKTsKCiAgICAgICAgaWYocmVzcCA9PSA5KSBicmVhazsKCiAgICAgICAgc3dpdGNoKHJlc3ApewogICAgICAgICAgICBjYXNlIDE6IC8v6Laz44GX566XCiAgICAgICAgICAgICAgICBhID0gcG9wKCk7CiAgICAgICAgICAgICAgICBiID0gcG9wKCk7CiAgICAgICAgICAgICAgICBwdXNoKGEgKyBiKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDI6IC8v5byV44GN566XCiAgICAgICAgICAgICAgICBhID0gcG9wKCk7CiAgICAgICAgICAgICAgICBiID0gcG9wKCk7CiAgICAgICAgICAgICAgICBwdXNoKGEgLSBiKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDM6IC8v5o6b44GR566XCiAgICAgICAgICAgICAgICBhID0gcG9wKCk7CiAgICAgICAgICAgICAgICBiID0gcG9wKCk7CiAgICAgICAgICAgICAgICBwdXNoKGEgKiBiKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDQ6IC8v5Ymy44KK566XCiAgICAgICAgICAgICAgICBhID0gcG9wKCk7CiAgICAgICAgICAgICAgICBiID0gcG9wKCk7CiAgICAgICAgICAgICAgICBwdXNoKGEgLyBiKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDU6IAogICAgICAgICAgICAgICAgcHJpbnRmKCJwdXNoIDogIik7CiAgICAgICAgICAgICAgICBzY2FuZigiJWQiLCAmZGF0YSk7CiAgICAgICAgICAgICAgICBwdXNoKGRhdGEpOwogICAgICAgICAgICAgICAgcHJpbnRmKCJkYXRhPSVkXG4iLCBkYXRhKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICAKICAgIH0KCiAgICBwcmludGYoIlxuIik7CiAgICBkaXNwbGF5KCk7CiAgICByZXR1cm4gMDsKfQoKdm9pZCBpbml0aWFsaXplKHZvaWQpewogICAgc3AgPSAwOwp9Cgp2b2lkIGRpc3BsYXkodm9pZCl7CiAgICBmb3IoaW50IGk9MDsgaTxzcDsgaSsrKXsKICAgICAgICBwcmludGYoImFuc3dlcjolbGZcbiIsc3RhY2tbaV0pOwogICAgfQp9CgppbnQgaXNGdWxsKHZvaWQpewogICAgaWYoc3AgPj0gU0laRSl7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9ZWxzZXsKICAgICAgICByZXR1cm4gMDsKICAgIH0KfQoKaW50IGlzRW1wdHkodm9pZCl7CiAgICBpZihzcCA8PSAwKXsKICAgICAgICByZXR1cm4gMTsKICAgIH1lbHNlewogICAgICAgIHJldHVybiAwOwogICAgfQp9Cgp2b2lkIHB1c2goZG91YmxlIHZhbHVlKQp7CiAgICBpZihpc0Z1bGwoKSl7CiAgICAgICAgcHJpbnRmKCLjgrnjgr/jg4Pjgq/jgYzmuoDmna/jgaflhaXjgorjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwogICAgfWVsc2V7CiAgICAgICAgc3RhY2tbc3ArK10gPSB2YWx1ZTsKICAgIH0KfQoKZG91YmxlIHBvcCh2b2lkKQp7CiAgICBpZihpc0VtcHR5KCkpewogICAgICAgIHByaW50Zigi44K544K/44OD44Kv44GM56m644Gn5Y+W44KK5Ye644Gb44G+44Gb44KT44Gn44GX44GfXG4iKTsKICAgICAgICByZXR1cm4gMDsKICAgIH1lbHNlewogICAgICAgIHJldHVybiBzdGFja1stLXNwXTsKICAgIH0KfQ==