C ++,695 + 510 = 1205字节
码:
#include<iostream>
#include<utility>
#include<vector>
#define D "\n#define "
using namespace std;using S=string;int main(){vector<pair<S,S>>m={{"--------","(*p)-=8;"},{"<>",""},{"[]","F;"},{"+","A;"},{"-","B;"},{">","C;"},{"<","D;"},{"[","F{"},{"]","}"},{".","E;"},{",","std::cin>>*p;"}};S s;char c;while(cin>>c)if(S("+-><[].,").find(c)<8)s+=c;for(int i=0;i<s.length();i++)if(s.substr(i,4)=="[][]")s=s.replace(i--,4,"[]");cout<<"#include<iostream>" D"A ++*p" D"B --*p" D"C p++" D"D p--" D"E std::cout<<*p" D"F while(*p)\nint main(){char*p=new char[1<<19]();";while(s.size())for(auto p:m)if(s.substr(0,p.first.length())==p.first){s=s.substr(p.first.length());cout<<p.second;break;}cout<<"}";}
输出:
#include<iostream>
#define A ++*p
#define B --*p
#define C p++
#define D p--
#define E std::cout<<*p
#define F while(*p)
int main(){char*p=new char[1<<19]();A;A;A;A;A;F{B;}A;A;A;A;A;A;A;A;A;A;F{C;A;A;A;A;A;A;A;C;A;A;A;A;A;A;A;A;A;A;C;A;A;A;D;D;D;B;}C;A;A;E;C;A;E;A;A;A;A;A;A;A;E;E;A;A;A;E;C;A;A;E;D;A;A;A;A;A;A;A;A;E;(*p)-=8;E;A;A;A;E;B;B;B;B;B;B;E;(*p)-=8;E;C;A;E;(*p)-=8;(*p)-=8;(*p)-=8;(*p)-=8;B;F{E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;E;}F;D;B;D;D;}
原始代码:
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
vector<pair<string, string>> m={
{"--------","(*p)-=8;"},
{"<>",""},
{"[]","F;"},
{"+","A;"},
{"-","B;"},
{">","C;"},
{"<","D;"},
{"[","F{"},
{"]","}"},
{".","E;"},
{",","std::cin>>*p;"}};
string s;
char c;
while (cin >> c)
if (string("+-><[].,").find(c) < 8)
s += c;
for(int i = 0; i < s.length(); i++)
if(s.substr(i, 4) == "[][]")
s = s.replace(i--, 4, "[]");
cout << "#include<iostream>\n"
"#define A ++*p\n"
"#define B --*p\n"
"#define C p++\n"
"#define D p--\n"
"#define E std::cout<<*p\n"
"#define F while(*p)\n"
"int main(){char*p=new char[1<<19]();";
while (s.size())
for (auto p : m)
if (s.substr(0, p.first.length()) == p.first) {
s = s.substr(p.first.length());
cout << p.second;
break;
}
cout << "}";
}