rochcim @ 2021-09-10 19:02:19
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
stack < char > p;
int main () {
char ch;
int s = 0;
do {
ch = getchar();
if (ch >= '0' && ch <= '9')
s = s * 10 + ch - '0';
else if (ch == '.'){
p.push(s);
s = 0;
}
else if (ch != '@'){
int x = p.top(); p.pop();
int y = p.top(); p.pop();
switch (ch) {
case '+': p.push(x + y); break;
case '-': p.push(y - x); break;
case '*': p.push(x * y); break;
case '/': p.push(y / x); break;
}
}
} while (ch != '@');
printf("%d\n", p.top());
return 0;
}
49 fen, qiu zhu, xie xie!
by Carnival @ 2021-09-10 19:17:39
@rochcim 为什么栈要用 char 类型?
by GODking @ 2021-09-10 19:30:23
push的时候不是int类型的s么?为什么要定义char类型的栈?
by Carnival @ 2021-09-10 19:31:38
我倒很好奇,为什么会拿到
by rochcim @ 2021-09-10 22:25:30
@白揍流星 哦哦改过来了,谢谢!
by rochcim @ 2021-09-10 22:26:15
@Gamemode 好神奇,六个里面WA了三个,得分49.。。不过改过来了,谢谢!
by GODking @ 2021-09-10 22:56:04
@rochcim 应该是四舍五入的问题