提交时间:2024-08-21 08:32:13

运行 ID: 173975

#include<bits/stdc++.h> using namespace std; char s[5000000];int len,ans[5000000],tot=1,key,key2; int add(int x,int place) { int i=place-1;bool z=true; key2=0; while(z) { i++; if(s[i]<='9'&&s[i]>='0') key2=key2*10+(s[i]-'0'); if(s[i]>'9'||s[i]<'0') break; } key%=10000; key2%=10000; key=(key*key2)%10000; return i-1; } int main() { int i=-1; gets(s); len=strlen(s); while(i<len) { i++; if(s[i]<='9'&&s[i]>='0') key=key*10+(s[i]-'0'); else if(s[i]!='*') { ans[tot]=key%10000; tot++; key=0; } else if(s[i]=='*') { i++; i=add(key,i); } } key=0; for(i=1;i<=tot;i++) key=(ans[i]+key)%10000; printf("%d",key); return 0; }