View Code of Problem 3855

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define PR printf
#define SC scanf
#define D "%ld"
int main()
{
  long t, i, j, k, f = 1;
  long num[400];
  char sp[2] = "";
  char res[1000];
  long des[100];
  char c[30];
  long n;
  SC("%ld", &t);
  for (i = 0; i < t; i++) {
    for (j = 0; j < 400; j++) num[j] = 0;
    n = 0;
    SC("%s", res);
    for (j = 0; j < strlen(res); j++) {
      if (res[j] < '9' && res[j] > '0') {
        num[n] = num[n] * 10 + res[j] - 48;
        //PR("num[%ld]=%ld,", n, num[n]);
      }
      else {
        num[n] *= f;
        n++;
        f = res[0] == '+' ? 1 : -1;
      }
    }
    des[i] = 0;
    for (j = 0; j <= n; j++) {
      des[i] += num[j];
      //PR("num[%ld]=%ld\n", j, num[j]);
    }
  }
  for (i = 0; i < t; i++) PR("%ld\n", des[i]);
 
  return 0;
}

Double click to view unformatted code.


Back to problem 3855