Rikka is a contestant in C-- Collegiate Programming Contest (CCPC), a competition for writing programs using a popular language C--.
A C-- expression is inductively defined in the following way.
-
arithmetic
performs some arithmetic calculations. -
library
invokes a function in the standard library of C--. -
For any C-- expression e and integer w∈[1,100],
repeat
efor
wtimes
repeats expression e for w times. -
For any two C-- expressions e1,e2, e1 e2 runs expressions e1,e2 in order.
A C-- program is a C-- expression followed by token fin
, representing the end of the program.
Today, Rikka takes part in the online selection of CCPC. She writes a C-- program, but it fails in passing all test cases. Now, Rikka wants to
figure out what goes wrong in this program using step debugging. However, such a choice is risky: Stepping into a library function of C-- may be judged as cheating.
Therefore, before debugging, Rikka wants to mature the risk of stepping into library functions. She wants to calculate how many times the C-- program invokes library functions.
样例1:
repeat library arithmetic for 5 times library arithmetic fin
6
样例2:
repeat library repeat repeat library for 3 times arithmetic library for 3 times for 100 times fin
1300
题意:
求library在字符串中的个数,本题的特殊之处在于,我们需要解析字符串中的循环,并输出结果
代码
#include <iostream>
using namespace std;
const int MOD=20220911;
int input(){
string str;
int ans=0;
while(cin>>str && str!="fin" && str[0]!='t'){
if(str[0]=='l')ans++;
else if(str[0]=='r')ans=(ans+input())%MOD;
else if(str[0]>='0' && str[0]<='9')ans=(ans*atoi(str.c_str()))%MOD;
}
return ans%MOD;
}
int main() {
cout<<input();
}