Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- Node node;
- int i, j;
- int total = 0;
- int cho = 0;
- int array1[1000];
- int array2[1000];
- Stack *s = makeStack();
- FILE *f = fopen("expreval.txt", "r");
- if (f == NULL)
- printf("FILE ERROR\n");
- else
- {
- fscanf(f, "%d", &n);
- for (i = 1; i <= n; i++)
- {
- fscanf(f, "%d", &array1[i]);
- }
- for (j = 1; j < n; j++)
- {
- fscanf(f, "%d", &array2[j]);
- }
- }
- for (i = 1; i <= n; i++)
- for (j = 1; j < n; j++)
- {
- pushStack(s, array1[i]);
- if(array2[j] == 2)
- {
- cho = topStack(s);
- popStack(s);
- cho = cho*array1[i];
- pushStack(s, cho);
- }
- }
- for(j = n-1; j >= 1; j--)
- {
- total = total + topStack(s);
- if(array2[j] == 0)
- total = total - topStack(s);
- if(array2[j] == 1)
- total = total + topStack(s);
- if(array2[j] == 2)
- total = total + topStack(s);
- }
- printf("%d\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement