- 孟令轩1 的博客
从字符中提取数字
- @ 2025-7-24 11:04:26
#include <iostream>
#include <string>
using namespace std;
int main() {
string expression;
cin >> expression;
int total = 0;
int current = 0;
for (char c : expression) {
if (isdigit(c)) {
current = current * 10 + (c - '0');
} else if (c == '+') {
total += current;
current = 0;
}
}
total += current;
cout << total << endl;
return 0;
}