编译器(C++)
#include <bits/stdc++.h>
#define int long long
using namespace std;
string s;
vector<string> p;
string ope;
map <string, int> bianliang;
signed main(){
while (cin >> s){
if (s == "RUN")
break;
p.push_back(s);
}
for (int x = 0; x < p.size(); x++){
string code = p[x];
if (ope == "in"){
int inputcode;
cin >> inputcode;
bianliang[code] = inputcode;
ope = "";
}
if (ope == "out"){
if (code == "NL")
cout << endl;
else if (code[0] == '"' && code[code.size() - 1] == '"')
cout << code;
else
cout << bianliang[code];
ope = "";
}
if (ope == "int"){
int now = 0;
int flag = 0;
string now_bl;
for (int i = 0; i < code.size(); i++){
if (code[i] == '='){
flag = 1;
continue;
}
if (flag == 0)
now_bl += code[i];
else
now = now * 10 + code[i] - '0';
}
bianliang[now_bl] = now;
ope = "";
}
if (code == "in")
ope = code;
if (code == "out")
ope = code;
if (code == "int")
ope = code;
}
return 0;
}运行方法
- 输入代码。
- 输入
RUN表示运行。 - 输入你要对程序进行的输入。
具体语法(仅目前支持)
- 定义整形变量 ,并赋值为 ,可以不赋值(默认为 )。
int x=10 //定义 x=10
int y //定义 y=0- 输出字符串、变量、换行。
out "luogu" //输出 luogu
out NL //输出换行
int x=100
out x //输出 x,即 100- 输入整形变量
int x
in x //输入 x
out x
in y //输入 y(若没有定义,则自动定义)
out y洛谷题目代码
https://www.luogu.com.cn/problem/B2002
out "Hello,World!"https://www.luogu.com.cn/problem/B2025
out " *"
out NL
out " ***"
out NL
out "*****"
out NL
out " ***"
out NL
out " *"