#4636: 程式碼很短 請幫我檢查出了什麼問題


stmharry (橘子皮)

學校 : 精誠中學
編號 : 14661
來源 : [140.112.218.161]
最後登入時間 :
2012-06-26 20:04:05
d016. 後序運算法 | From: [125.224.122.199] | 發表日期 : 2010-12-05 17:51

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string input;
    
    while(getline(cin, input))
    {
                         int *buffer=new int[input.length()];
                         int store=-1;
                         
                         for(int read=0; input[read]!='\0'; read++)
                         {
                                 if( (47<input[read]) && (input[read]<58) ) buffer[++store]=(int)(input[read]-48);
                                 else if(input[read]=='+') buffer[store-1]+=buffer[store--];
                                 else if(input[read]=='-') buffer[store-1]-=buffer[store--];
                                 else if(input[read]=='*') buffer[store-1]*=buffer[store--];
                                 else if(input[read]=='/') buffer[store-1]/=buffer[store--];
                                 else if(input[read]=='%') buffer[store-1]%=buffer[store--];
                                 
                         }
                         
                         cout << buffer[0] << endl;
                         delete [] buffer;
    }
    
    return 0;
}
 
範例測資都沒問題啊
 
可是WA:line3了 

 
#4640: Re:程式碼很短 請幫我檢查出了什麼問題


stmharry (橘子皮)

學校 : 精誠中學
編號 : 14661
來源 : [140.112.218.161]
最後登入時間 :
2012-06-26 20:04:05
d016. 後序運算法 | From: [125.224.120.89] | 發表日期 : 2010-12-06 22:19

#include
#include
using namespace std;

int main()
{
    string input;
    
    while(getline(cin, input))
    {
                         int *buffer=new int[input.length()];
                         int store=-1;
                         
                         for(int read=0; input[read]!='\0'; read++)
                         {
                                 if( (47
                                 else if(input[read]=='+') buffer[store-1]+=buffer[store--];
                                 else if(input[read]=='-') buffer[store-1]-=buffer[store--];
                                 else if(input[read]=='*') buffer[store-1]*=buffer[store--];
                                 else if(input[read]=='/') buffer[store-1]/=buffer[store--];
                                 else if(input[read]=='%') buffer[store-1]%=buffer[store--];
                                 
                         }
                         
                         cout << buffer[0] << endl;
                         delete [] buffer;
    }
    
    return 0;
}
 
範例測資都沒問題啊
 
可是WA:line3了 

 
我知道了= =
只能取一位XD 
 
ZeroJudge Forum