社区讨论
80分求调
P1322logo语言参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mjip01h7
- 此快照首次捕获于
- 2025/12/23 22:40 3 个月前
- 此快照最后确认于
- 2025/12/26 18:30 2 个月前
CPP
#include<iostream>
#include<cmath>
#include<stack>
#define FD(foward) step += foward
#define BK(back) step -= back
#define REPEAT(cs,command) for(int k = 0;k < cs-1;k++) dg(command)/*,cout<<command<<" now:"<<step<<endl*/
using namespace std;
int step = 0;
stack<char> pare;
int find_last_of(string str,int now_pos){
for(int i = now_pos;i < str.length();i++){
if(str[i] == '['){
pare.push('[');
}
else if(str[i] == ']'){
pare.pop();
}
if(pare.empty()){
return i;
}
}
stack<char>().swap(pare);
return -1;
}
void dg(string command){
for(int i = 0;i < command.length();i++){
if(command[i] == 'F' && command[i+1] == 'D'){
string mem = "";
for(int j = i+3;command[j] != ' ' && command[j] != ']';j++){
mem+=command[j];
}
FD(stoi(mem));
}
if(command[i] == 'B' && command[i+1] == 'K'){
string mem = "";
for(int j = i+3;command[j] != ' ' && command[j] != ']';j++){
mem+=command[j];
}
BK(stoi(mem));
}
if(command[i] == 'R' && command[i+1] == 'E' && command[i+2] == 'P' && command[i+3] == 'E' && command[i+4] == 'A' && command[i+5] == 'T'){
string mem = "";
int poslast = 0;
for(int j = i+7;command[j] != ' ' && command[j] != '[';j++){
mem+=command[j];
}
poslast = find_last_of(command,i+7+mem.length());
REPEAT(stoi(mem),command.substr(i+7+mem.length()-2,poslast+2-(i+7+mem.length())));
}
}
}
int main(){
string str;
getline(cin,str);
dg(str);
cout<<abs(step)<<endl;
return 0;
}
有帮助必关
回复
共 0 条回复,欢迎继续交流。
正在加载回复...