Advertisement
nguyentruong98

Untitled

Dec 14th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. int main()
  2. {
  3.       Node node;
  4.       int i, j;
  5.       int total = 0;
  6.       int cho = 0;
  7.       int array1[1000];
  8.       int array2[1000];
  9.       Stack *s = makeStack();
  10.       FILE *f = fopen("expreval.txt", "r");
  11.       if (f == NULL)
  12.             printf("FILE ERROR\n");
  13.       else
  14.       {
  15.             fscanf(f, "%d", &n);
  16.             for (i = 1; i <= n; i++)
  17.             {
  18.                   fscanf(f, "%d", &array1[i]);
  19.             }
  20.             for (j = 1; j < n; j++)
  21.             {
  22.                   fscanf(f, "%d", &array2[j]);
  23.             }
  24.       }
  25.       for (i = 1; i <= n; i++)
  26.             for (j = 1; j < n; j++)
  27.             {
  28.                   pushStack(s, array1[i]);
  29.                  if(array2[j] == 2)
  30.                  {
  31.                        cho = topStack(s);
  32.                        popStack(s);
  33.                        cho = cho*array1[i];
  34.                        pushStack(s, cho);
  35.                  }
  36.             }
  37.       for(j = n-1; j >= 1; j--)
  38.       {
  39.             total = total + topStack(s);
  40.             if(array2[j] == 0)
  41.             total = total - topStack(s);
  42.             if(array2[j] == 1)
  43.             total = total + topStack(s);
  44.             if(array2[j] == 2)
  45.             total = total + topStack(s);
  46.       }
  47.       printf("%d\n", total);
  48.       return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement