#7627: WA


heyuezhou (s09689761)

學校 : 澳門培正中學
編號 : 20926
來源 : [119.74.44.213]
最後登入時間 :
2023-06-01 23:38:51
b061. 6. 糊塗情報員 -- 95學年度全國資訊學科能力競賽 | From: [60.246.230.145] | 發表日期 : 2013-03-27 21:58

#include<iostream>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<sstream>
#include<algorithm>
using namespace std;
string s;
int len;
int max1[1000][1000];
int min1[1000][1000];
int oper(char a, char b,char c)
{
    int a1,c1;
    stringstream ss;
    ss<<a;
    ss>>a1;
    stringstream ss2;
    ss2<<c;
    ss2>>c1;

    if (b=='*') return  a1*c1;
    if (b=='/') return  a1/c1;
    if (b=='+') return  a1+c1;
    if (b=='-') return  a1-c1;
}
int oper2(int a, char b,int c)
{
    if (b=='*') return a*c;
    if (b=='/') return a/c;
    if (b=='+') return a+c;
    if (b=='-') return a-c;
}
void dp(int st,int en)

{
 if (en-st<=2)
{
 if (en-st==2)
  {
  max1[st][en]=oper(s[st],s[st+1],s[en]);
  min1[st][en]=oper(s[st],s[st+1],s[en]);           
  }
  else
  {
   max1[st][en]=s[st]-'0';
   min1[st][en]=s[st]-'0';
  }
 }
  else

    {

    int i,k,c=0;
    int cmax,cmin;
     int t[4];
     cmax=-2147483647; cmin=2147483647;
     for (i=st+1;i<=en-1;i++)

      {

       if (not isdigit(s[i]))
        { 
         if (max1[st][i-1]==0)
   {dp(st,i-1);}
     if (max1[i+1][en]==0)
  {dp(i+1,en);}
       
        
         t[0]=oper2(max1[st][i-1],s[i],max1[i+1][en]);
          t[1]=oper2(max1[st][i-1],s[i],min1[i+1][en]);
           t[2]=oper2(min1[st][i-1],s[i],max1[i+1][en]);
            t[3]=oper2(min1[st][i-1],s[i],min1[i+1][en]);
            int j;
             for (j=0;j<=3;j++)
              {if  (t[j]>cmax){cmax=t[j];}
               if  (t[j]<cmin) {cmin=t[j];}
              }
           }
           max1[st][en]=cmax;
           min1[st][en]=cmin;
      }


   }

}

int main()

{


while (cin>>s)
{
memeset(max1,0,sizeof(max1));
memeset(max2,0,sizeof(max2));
s=' '+s;
len=s.length();
dp(1,len-1);
cout<<max1[1][len-1]<<endl;
}
return 0;

}

為甚麼會WA....59

 

 
ZeroJudge Forum