站外题求助(玄关)

学术版

@[C112345565_](/user/1073331) The ans: ```cpp #include <bits/stdc++.h> using namespace std; stack<long long> sta; char a[1001]; int main() { cin.getline(a, 1001); long long temp = 0, x = 0, y = 0; for (int i = 0; a[i] != '@'; i++) { x = 0, y = 0; if (a[i] >= '0' && a[i] <= '9') temp = temp * 10 + (a[i] - '0'); else if (a[i] == ' ' || a[i] == '.') sta.push(temp), temp = 0; else { y = sta.top(); sta.pop(); x = sta.top(); sta.pop(); switch (a[i]) { case '+': {sta.push(x + y); break;} case '-': {sta.push(x - y); break;} case '*': {sta.push(x * y); break;} case '/': {sta.push(x / y); break;} } } } cout << sta.top(); return 0; } ```
by Enoch2013 @ 2024-04-13 15:37:22


@[C112345565_](/user/1073331) 你要用栈,读入有用$cin.getline()$
by Enoch2013 @ 2024-04-13 15:38:41


@[Enoch2013](/user/1069719) 感谢感谢,已关
by C112345565_ @ 2024-04-13 15:40:23


|