码蹄杯 小码哥与机器人 题型:模拟

62 阅读1分钟

码题集OJ-小码哥与机器人 (matiji.net)

image.png 样例输入:

REPEAT 5[ FD 50 REPEAT 10[FD 100]]

样例输出:

5250

思想

首先

code

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ans;

LL solve()
{
	string s;
	char c,k;
	LL n,ans=0;
	while(cin>>c)  //针对每个字符
	{
		if(c==']') break;  //当读取到']'时程序就结束了
		
		cin>>s>>n;        //读取一个命令 和 命令参数
		if(c=='R')        //如果是REPEAT命令
		{
			cin>>k;  //把REPEAT命令后面的k值读取掉
			ans+=n*solve(); 
		}
		if(c=='B') ans-=n;
		if(c=='F') ans+=n;
	}
return ans;
}
int main()
{
    cout<<abs(solve())	;
    return 0;
}

image.png