Files
python/LuoGu/RuMen/P2788.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

49 lines
1.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
char a[1010101];//KAO,第一次下手不够狠居然RE了两个点
queue<string> q1;
queue<char> q2;
int main() {
scanf("%s", a);
string s1 = "", s2 = "";
for (int i = 0; a[i] != '\0';) {
//数字
while (a[i] >= '0' && a[i] <= '9') {
s1 += a[i];
i++;
}
if (s1.size() > 0) {
q1.push(s1);
s1.clear();
}
//操作符
if (a[i] == '+' || a[i] == '-') {
q2.push(a[i]);
i++;
}
}
long result;
//字符串转数字长整型
istringstream(q1.front()) >> result;
q1.pop();
while (!q1.empty()) {
long second;
istringstream(q1.front()) >> second;
q1.pop();
char c = q2.front();
q2.pop();
if (c == '+') {
result += second;
} else {
result -= second;
}
}
cout << result << endl;
return 0;
}