2022 ICPC网络赛第一场-H Step Debugging

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 e for w times 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();
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值