// Verdict:: Accepted
// Time:: 0.000
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint(a,b) scanf("%d %d",&a,&b)
#define sfl(a,b) scanf("%ld %ld",&a,&b)
#define sfll(a,b) scanf("%lld %lld",&a,&b)
#define sfd(a,b) scanf("%lf %lf",&a,&b)
#define sff(a,b) scanf("%f %f",&a,&b)
#define lp1(i,n) for(i=0;i<n;i++)
#define lp2(i,n) for(i=1;i<=n;i++)
#define LL long long
#define L long
#define mem(c,v) memset(c,v,sizeof(c))
#define ui unsigned int
#define cp(a) cout<<" "<<a<<" "<<endl
#define ull unsigned long long int
#define nl puts("")
#define sq(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define mx7 20000100
#define mx6 1500000
#define mx5 100005
#define inf 1<<30 //infinity value
#define eps 1e-9
#define mx (65540)
#define mod 1000000007
#define pb push_back
#define pbck pop_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
using namespace std;
//.......................................................................................................
template<class T> T setbit(T n, T pos){n=n|(1<<pos); return n;}
template<class T> T checkbit(T n, T pos){n=n&(1<<pos); return n;}
template<class T> T gcd(T a, T b ) {return b==0?a:gcd(b,a%b);}
template<class T> T large(T a, T b ) {return a>b?a:b;}
template<class T> T small(T a, T b ) {return a<b?a:b;}
#define add 0
#define ml -1
void for_minimum();
void for_maximum();
vector<LL>vmin,vmax; // declared two vectors
int main()
{
LL t;
char ch[1001];
sf("%lld\n",&t);
while(t--) {
sf("%s",&ch);
LL slen=strlen(ch);
LL r=0,b=-1,d;
for(LL i=0;i<=slen;i++)
{
//pf("%c ",ch[i]);
if(ch[i]=='+')
{
d=i;
r=0;
for(LL j=b+1;j<d;j++)
{
r=(ch[j]-48)+(r*10);
}
vmin.push_back(r);
b=d;
r=0;
vmin.push_back(add);
}
else if(ch[i]=='*')
{
d=i;
for(LL j=b+1;j<d;j++)
{
r=(ch[j]-48)+(r*10);
}
vmin.push_back(r);
b=d;
r=0;
vmin.push_back(ml);
}
else if(ch[i]=='\0')
{
d=i;
for(LL j=b+1;j<d;j++)
{
r=(ch[j]-48)+(r*10);
}
vmin.push_back(r);
r=0;
b=d;
}
}
// for(LL i=0;i<vmin.size();i++)
// {
// cout<<vmin[i] << " ";
// } nl;
vmax=vmin; // copied vectors
pf("The maximum and minimum are ");
for_maximum();
for_minimum();
vmin.clear();
vmax.clear();
}
}
void for_minimum()
{
LL i=0,len=vmin.sz;
for(i=0;i<len;i++)
{
if(vmin[i]==ml)
{
vmin[i+1]=vmin[i+1] * vmin[i-1];
vmin[i]=add;
vmin[i-1]=add;
}
}
//lp1(i,vmin.sz)cout << vmin[i];
//nl;
LL ans=0;
for(i=0;i<len;i++)
{
if(vmin[i]==add)
{
continue;
}
ans+=vmin[i];
}
pf("%lld.\n",ans);
//vmin.clear();
}
void for_maximum()
{
LL i=0,len=vmax.size(),ans=1;
for(i=0;i<len;i++)
{
if(vmax[i]==add)
{
vmax[i+1]=vmax[i+1] + vmax[i-1];
vmax[i]=ml;
vmax[i-1]=ml;
}
}
//lp1(i,vmax.sz)cout << vmax[i] << " "; nl;
lp1(i,len)
{
if(vmax[i]==ml)
{
continue;
}
ans*=vmax[i];
}
pf("%lld and ",ans);
//vmax.clear();
}
Comments
Post a Comment