1 solutions
-
0
C++ :
#include <stdio.h> #include <string.h> #include <ctype.h> #define ADD 1002 #define MIN 1003 #define MAX 1004 int optrStack[301],ptr; int pop(){return optrStack[--ptr];} void push(int n){optrStack[ptr++]=n;} void readOptr(char *s,int &now){ if(s[1]=='d') push(ADD); else if(s[1]=='i') push(MIN); else push(MAX); now+=4; } void readNum(char *s,int &now){ int n,i=0; sscanf(s,"%d",&n); push(n); while(s[i]!=','&&s[i]!=')'){ now++; i++; } } void operate(int &now){ int a,b,opt; b=pop(); a=pop(); opt=pop(); if(opt==ADD) push(a+b); else if(opt==MIN) push(a>b?b:a); else push(a<b?b:a); now++; } int main(){ int n,len,i; char data[301]; scanf("%d",&n); while(n--){ scanf("%s",data); len=strlen(data); i=ptr=0; while(i<len){ if(isalpha(data[i])) readOptr(&data[i],i); else if(isalnum(data[i])) readNum(&data[i],i); else if(data[i]==',') i++; else operate(i); } printf("%d\n",pop()); } }
- 1
Information
- ID
- 19023
- Time
- 3000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By