This repository has been archived on 2023-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_cpp/term1/seminar03_initialization/05_string_sum/main.cpp

36 lines
683 B
C++
Raw Normal View History

2023-02-25 19:34:24 +03:00
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int string_sum(const string& str) {
int res = 0;
int x;
int n = str.size();
int i = 0;
while (i < n) {
switch (str[i]) {
case '[':
case ',' :
sscanf((str.c_str()) + i + 1, "%d", &x);
res += x;
break;
case ']' :
return res;
case ' ':
break;
default:
break;
}
++i;
}
return -1;
}
int main() {
string meow;
getline(cin, meow);
cout << string_sum(meow) << endl;
}