|Tyvj|NOIP2013|模拟|P2772 表达式求值

来源:互联网 发布:手游java服务器端源码 编辑:程序博客网 时间:2024/05/01 15:29

http://tyvj.cn/p/2772

此题由于我不喜欢用栈写表达式(分明是不会),所以用个链表乱搞AC了。。

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int sz[100005];//数字 int bh[100005];//标号,链表储存 int s_n = 0;char fh[100005];//符号 int f_n = 0;char lastch=' ',ch;int main () { //freopen("123.in","r", stdin);memset(sz, 0, sizeof(sz));int i = 0;ch = getchar();while(ch!='\n'){if (ch=='+'||ch=='*') fh[++f_n] = ch;if (ch>='0'&&ch<='9'){if(lastch>='0'&&lastch<='9'){sz[s_n] = (sz[s_n] * 10 + ch - '0') % 10000;} else sz[++s_n] = ch - '0';}lastch = ch;ch = getchar();} for (int i=1;i<=s_n;i++) bh[i] = i+1;bh[s_n] = 10000000;for (int i=1;i<=f_n;i++){if(fh[i]=='*'){sz[bh[i]] = sz[i] * sz[bh[i]] % 10000;sz[i] = 765428;}}int tot = 0;for (int i=1;i<=s_n;i=bh[i]){if (sz[i]!=765428)tot = (tot+sz[i])%10000;}printf("%d\n", tot);return 0;}


0 0
原创粉丝点击