这道题一开始TLE,卡了5分钟后,依旧全TLE。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;
const int Maxn = 1e6 + 1;
int main()
{
register string S;
cin >> S;
register int stack[Maxn]/*栈*/, top = 0;
register int x;
for(register int tp = 0; tp < S.length(); ++tp)
{
register int h = 1;
x = 0;
if('0' <= S[tp] && S[tp] <= '9')
{
x = S[tp] - '0';
while('0' <= S[tp + h] && S[tp + h] <= '9')
{
x = (x << 3) + (x << 1) + (S[tp + h] - '0');
x %= 1000;
}
tp += h;
}
if(S[tp] == '*')
{
while(S[tp] == '*')
{
++tp;
h = 1;
int p;
p = S[tp] - '0';
while('0' <= S[tp + h] && S[tp + h] <= '9')
{
p = (p << 3) + (p << 1) + (S[tp + h] - '0');
p %= 1000;
}
stack[++top] = (p * x) % 1000;
tp += h;
}
}
else
{
stack[++top] = x;
x = 0;
}
}
register int ans = 0;
for(int i = 1; i <= top; i++)
{
ans += stack[i];
ans %= 1000;
}
printf("%d\n", ans);
return 0;
}