传送门
https://www.cnblogs.com/violet-acmer/p/9898636.html
题解:
哇哇哇,又是一发暴力AC.
用字符数组存储表达式。
然后将表达式中的 数字 与 运算符号 分开。
两次for( )循环
第一次循环找到所有的 ' * ' 运算符,并把 ' * ' 前的整数乘到 ' * ' 后的整数上,并将 ' * ' 前的整数赋值为 0;
第二次遍历,将所有的数加起来就是答案。
所有中间结果别忘了膜 10000,最终答案也要膜 10000
AC代码:


#include<bits/stdc++.h> using namespace std; const int maxn=2e6; const int mod=10000;char s[maxn]; char op[maxn]; int num[maxn];int Trans()//将整数与运算符分离 {int tot=0;int len=strlen(s);int v=0;for(int i=0;i < len;++i){if(s[i] == '*' || s[i] == '+'){op[++tot]=s[i];num[tot]=v;v=0;}elsev=v*10+(s[i]-'0');}num[++tot]=v;//不要忘了存储最后一个整数return tot; } void Solve() {int tot=Trans();int res=0;//把 ' * ' 前的整数乘到 ' * ' 后的整数上,并将 ' * ' 前的整数赋值为 0for(int i=1;i < tot;++i)if(op[i] == '*')num[i+1]=num[i+1]%mod*(num[i]%mod),num[i]=0;for(int i=1;i <= tot;++i)res=res%mod+num[i];printf("%d\n",res%mod); } int main() {scanf("%s",s);Solve(); }