您的位置:首页 > 其它

NOIP2013普及组 T2 表达式求值

2016-05-02 16:42 323 查看
OJ地址:洛谷P1981 CODEVS 3292

正常写法是用栈

/*NOIP2013普及组t2 洛谷P1981 表达式求值*/
/**/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
char last;
char c;
int x=0;
int a=0,b=1;
int sum=0;
int main(){
int i,j;
bool flag=1;
do{
if(cin>>c);
else{
flag=0;
c='+';//相当于在整个串最后补个+号,以完成全部运算
}
if(c>='0' && c<='9')x=x*10+c-'0';
else{
a=x;
x=0;
}
if(c=='*'){
last=1;
b=(a*b)%10000;
}
if(c=='+'){
if(last){
a=(a*b)%10000;
sum=(sum+a)%10000;
b=1;
last=0;
}
else sum+=a;
}

}while(flag==1);
printf("%d",sum%10000);
return 0;
}


诡异写法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: