fork(1) download
  1. #include <cstring>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. setlocale(LC_CTYPE, "rus");
  8. cout << "Введите строку: ";
  9. char arr[100], num[10], znak = '+';
  10. int summa = 0;
  11. cin.getline(arr, 100);
  12. for (int i = 0, j = 0; i < strlen(arr); i++)
  13. {
  14. if (strchr("+-", arr[i]))
  15. {
  16. if (znak == '+')
  17. summa += atoi(num);
  18. else
  19. summa -= atoi(num);
  20. j = 0;
  21. num[0] = '\0';
  22. znak = arr[i];
  23. }
  24. else
  25. {
  26. num[j++] = arr[i];
  27. num[j] = '\0';
  28. }
  29. }
  30. if (znak == '+')
  31. summa += atoi(num);
  32. else
  33. summa -= atoi(num);
  34. cout << arr << " = " << summa << endl;
  35. system("pause");
  36. return 0;
  37. }
Success #stdin #stdout #stderr 0s 5048KB
stdin
3+3-5
stdout
Введите строку: 3+3-5 = 1
stderr
sh: pause: not found