P1449 后缀表达式
本文最后更新于 173 天前,其中的信息可能已经有所发展或是发生改变。

https://www.luogu.com.cn/problem/P1449

//自认为代码清晰,需要注意的地方只有"-"、"/"时y,z的顺序即可
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long LL;
typedef list<int>::iterator Iter;
list<int> L;
deque<int> dq;
queue<int> q;
stack<int> s;
vector<int> a(N + 1, 0);
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char ch;
    int x = 0, y = 0, z = 0, ans = 0;
    while (ch != '@') {
        ch = getchar();
        if (ch == '.') {s.push(x);x = 0;}
        else if (ch == '*') {y = s.top();s.pop();z = s.top();s.pop();ans = y * z;s.push(ans);}
        else if (ch == '/') {y = s.top();s.pop();z = s.top();s.pop();ans = z / y;s.push(ans);}
        else if (ch == '+') {y = s.top();s.pop();z = s.top();s.pop();ans = y + z;s.push(ans);}
        else if (ch == '-') {y = s.top();s.pop();z = s.top();s.pop();ans = z - y;s.push(ans);}
        else x = x * 10 + (ch - '0');
    }
    cout << s.top();
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇