#include <iostream>
using namespace std;
void solve(){
int res = 0;
string s, cur;
cin >> s;
for(int i = 0; i < s.length(); i++){
if(s[i] == '+' || s[i] == '-'){
res += stoi(cur);
cur = s[i];
}
else{
cur += s[i];
if(!cur.empty()) res += stoi(cur);
cout << res;
signed main() {
solve();
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
void solve(){
int res = 0;
string s, cur;
cin >> s;
for(int i = 0; i < s.length(); i++){
if(s[i] == '+' || s[i] == '-'){
res += stoi(cur);
cur = s[i];
}
else{
cur += s[i];
}
}
if(!cur.empty()) res += stoi(cur);
cout << res;
}
signed main() {
solve();
}