Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

struct stk
{
    
int n[10001], top;
    stk()
    {
        memset(n, 
0sizeof n);
    }
    
int pop()
    {
        
if(top > 0)
            
return n[top--];
        
else
            
return 0;
    }
    
void push(int x)
    {
        n[
++top] = x;
    }
    
void clr()
    {
        top 
= 0;
        memset(n, 
0sizeof n);
    }
}sample;

int main()
{
    
int x = 0;
    
string s;
    cin 
>> s;
    
for(int i = 0; s[i] != '@'; i++)
    {
        
if(s[i] != '.')
            x 
= x * 10 + s[i] - '0';
        
if(s[i] == '.')
            
if(x != 0)
            {
                sample.push(x);
                x 
= 0;
            }

        
switch(s[i])
        {
            
case '+':
                     x 
= sample.pop();
                     sample.n[sample.top] 
+= x;
                     x 
= 0;break;
            
case '-':
                     x 
= sample.pop();
                     sample.n[sample.top] 
-= x;
                     x 
= 0;break;
            
case '*':
                     x 
= sample.pop();
                     sample.n[sample.top] 
*= x;
                     x 
= 0;break;
            
case '/':
                     x 
= sample.pop();
                     sample.n[sample.top] 
/= x;
                     x 
= 0;break;
        }
    }

    cout 
<< sample.n[sample.top] << endl;

    
return 0;
}

posted on 2009-09-15 21:27 mad4alcohol 阅读(86) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理