fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main() {
  7. ifstream fin("matematica.in");
  8. ofstream fout("matematica.out");
  9. long long rez = 0, c, min = 1<<50;
  10. bool semn = 1;
  11. char ex[1010];
  12. cin >> c;
  13. cin.get();
  14. cin.getline(ex, 1008);
  15. long n = strlen(ex);
  16. long long termen = 0;
  17. for(long long i = 0; i < n; i++) {
  18. if(isdigit(ex[i])) {
  19. termen = termen * 10 + ex[i] - '0';
  20. } else {
  21. if(semn) {
  22. rez += termen;
  23. if(min > termen) {
  24. min = termen;
  25. }
  26. } else {
  27. rez -= termen;
  28. if(min > -termen) {
  29. min = -termen;
  30. }
  31. }
  32. termen = 0;
  33. if(ex[i] == '-') {
  34. semn = 0;
  35. } else {
  36. semn = 1;
  37. }
  38. }
  39. }
  40. if(semn) {
  41. rez += termen;
  42. if(min > termen) {
  43. min = termen;
  44. }
  45. } else {
  46. rez -= termen;
  47. if(min > -termen) {
  48. min = -termen;
  49. }
  50. }
  51. if(c == 1) {
  52. cout << rez;
  53. } else {
  54. cout << rez - 2 * min;
  55. }
  56. }
  57.  
Success #stdin #stdout 0.01s 5280KB
stdin
1
-0+1
stdout
1