View Code of Problem 3855

#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int T; cin >> T;
	while (T--) {
		string str; cin >> str;
		int ans = 0;
		string s = str.substr(0, 1);
		for (int i = 1; i < str.size(); i++) {
			if (isdigit(str[i])) s += str[i];
			else {
				ans += stoi(s);
				s.clear();
				s += str[i];
			}
		}
		ans += stoi(s);
		cout << ans << endl;
	}
		
}

Double click to view unformatted code.


Back to problem 3855