码迷,mamicode.com
首页 > 其他好文 > 详细

表达式求值

时间:2015-01-09 20:51:32      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

#include<cstdio>
#include<iostream>
using namespace std;
long long a[1000001];
char c[1000001];
int main()
{
int i=2;
cin>>a[1];
int ans=0;
while(scanf("%c",&c[i++])!=EOF)
scanf("%d",&a[i++]);
i-=2;
for(int j=i;j>0;j--)
if(c[j]==‘*‘){a[j-1]*=a[j+1];a[j-1]%=10000;}
for(int j=1;j<=i;j++)
if(c[j]==‘+‘){ans+=a[j+1];ans%=10000;}
cout<<(ans+a[1])%10000;
return 0;
}

表达式求值

标签:

原文地址:http://www.cnblogs.com/SSYYGAM/p/4214019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!