Created
December 24, 2023 15:06
-
-
Save ten986/1b2cfb72c3776ac52ddd8b0f9324ff36 to your computer and use it in GitHub Desktop.
2023年アドベントカレンダーで使用したMalbolgeの変換機です
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const std::string opcode_decode_table = | |
R"(+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA"lI.v%{gJh4G\-=O@5`_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha)"; | |
const std::string op = R"(ji*p</v)"; | |
int main() | |
{ | |
int address = 0; | |
while(true){ | |
int op; | |
cin >> op; | |
if(op == 11){ | |
// 11 -> 次の文字列を、変換後のものにする | |
string str; | |
cin >> str; | |
for(int i = 0; i < str.length(); ++ i){ | |
char c = str[i]; | |
auto opcode_idx = opcode_decode_table.find(c); | |
int data = ((opcode_idx - address + opcode_decode_table.length() * 10000) % opcode_decode_table.length() + opcode_decode_table.length()) % opcode_decode_table.length() + 33; | |
cout << (char)data; | |
address++; | |
} | |
} else | |
if(op == 12){ | |
// 12 -> 次の文字列を、変換後のものにする | |
char c; | |
int N; | |
cin >> c >> N; | |
auto opcode_idx = opcode_decode_table.find(c); | |
for (int i = 0; i < N; ++i){ | |
int data = ((opcode_idx - address + opcode_decode_table.length() * 10000) % opcode_decode_table.length() + opcode_decode_table.length()) % opcode_decode_table.length() + 33; | |
cout << (char)data; | |
address++; | |
} | |
} else | |
if(op == 13){ | |
// 13 -> 次の文字を、address が N になるまで変換後のもので置く | |
char c; | |
int N; | |
cin >> c >> N; | |
auto opcode_idx = opcode_decode_table.find(c); | |
while (address != N){ | |
if (address > N) { | |
cout << endl << "ERROR!" << endl; | |
break; | |
} | |
int data = ((opcode_idx - address + opcode_decode_table.length() * 10000) % opcode_decode_table.length() + opcode_decode_table.length()) % opcode_decode_table.length() + 33; | |
cout << (char)data; | |
address++; | |
} | |
} else | |
if(op == -1){ | |
break; | |
} else | |
if (op == 0){ | |
while(true){ | |
string s; | |
cin >> s; | |
if(s == "#"){ | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment