#include #include #include #include #include #include using namespace std; int main(){ int nums[100]; int opers[100]; // 1=+ 2=* bool mode = 1; // 1 no 0 op char ch; int l; ch = getchar(); while(ch != 'E'){ l = 0; mode = 1; while(ch != '\n'){ int no = 0; while(int(ch) >= int('0') && int(ch) <= int('9')){ no *= 10; no += int(ch)-int('0'); ch = getchar(); } nums[l] = no; if(ch == '+') opers[l] = 1; if(ch == '*') opers[l] = 2; if(ch == '+' || ch == '*'){ch = getchar(); l++;} } int aprod = nums[0]; int products = 1; for(int i = 0; i < l; i++){ if(opers[i] == 1) aprod += nums[i+1]; else{ products*=aprod; aprod = nums[i+1]; } } products *= aprod; int adding = 0; aprod = nums[0]; for(int i = 0; i < l; i++){ if(opers[i] == 1){ adding += aprod; aprod = nums[i+1]; } else{ aprod *= nums[i+1]; } } adding += aprod; printf("%d %d\n", min(products, adding), max(products, adding)); ch = getchar(); } return 0; }