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;
  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++) {
    f = 1;
    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;
      }
      else {
        num[n] *= f;
        n++;
        f = res[j] == '+' ? 1 : -1;
      }
    }
    num[n] *= f;
    des[i] = 0;
    for (j = 0; j <= n; j++) {
      des[i] += num[j];
      //PR("\nnum[%ld]=%ld: ", 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