#include <cstring>
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_CTYPE, "rus");
cout << "Введите строку: ";
char arr[100], num[10], znak = '+';
int summa = 0;
cin.getline(arr, 100);
for (int i = 0, j = 0; i < strlen(arr); i++)
{
if (strchr("+-", arr[i]))
{
if (znak == '+')
summa += atoi(num);
else
summa -= atoi(num);
j = 0;
num[0] = '\0';
znak = arr[i];
}
else
{
num[j++] = arr[i];
num[j] = '\0';
}
}
if (znak == '+')
summa += atoi(num);
else
summa -= atoi(num);
cout << arr << " = " << summa << endl;
system("pause");
return 0;
}
I2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAppbnQgbWFpbigpCnsKICAgIHNldGxvY2FsZShMQ19DVFlQRSwgInJ1cyIpOwogICAgY291dCA8PCAi0JLQstC10LTQuNGC0LUg0YHRgtGA0L7QutGDOiAiOwogICAgY2hhciBhcnJbMTAwXSwgbnVtWzEwXSwgem5hayA9ICcrJzsKICAgIGludCBzdW1tYSA9IDA7CiAgICBjaW4uZ2V0bGluZShhcnIsIDEwMCk7CiAgICBmb3IgKGludCBpID0gMCwgaiA9IDA7IGkgPCBzdHJsZW4oYXJyKTsgaSsrKQogICAgewogICAgICAgIGlmIChzdHJjaHIoIistIiwgYXJyW2ldKSkKICAgICAgICB7CiAgICAgICAgICAgIGlmICh6bmFrID09ICcrJykKICAgICAgICAgICAgICAgIHN1bW1hICs9IGF0b2kobnVtKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgc3VtbWEgLT0gYXRvaShudW0pOwogICAgICAgICAgICBqID0gMDsKICAgICAgICAgICAgbnVtWzBdID0gJ1wwJzsKICAgICAgICAgICAgem5hayA9IGFycltpXTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgbnVtW2orK10gPSBhcnJbaV07CiAgICAgICAgICAgIG51bVtqXSA9ICdcMCc7CiAgICAgICAgfQogICAgfQogICAgaWYgKHpuYWsgPT0gJysnKSAKICAgICAgICBzdW1tYSArPSBhdG9pKG51bSk7CiAgICBlbHNlIAogICAgICAgIHN1bW1hIC09IGF0b2kobnVtKTsKICAgIGNvdXQgPDwgYXJyIDw8ICIgPSAiIDw8IHN1bW1hIDw8IGVuZGw7CiAgICBzeXN0ZW0oInBhdXNlIik7CiAgICByZXR1cm4gMDsKfQ==