0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 19:45:24 +00:00

734. 【统一省选2022】预处理器

https://uoj.ac/submission/563016
This commit is contained in:
Baoshuo Ren 2022-07-10 09:38:16 +08:00
parent 2170149cca
commit 8e52eb7916
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
25 changed files with 141 additions and 0 deletions

69
UniversalOJ/734/734.cpp Normal file
View File

@ -0,0 +1,69 @@
#include <cstdio>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105;
int n;
std::string s[N];
std::unordered_map<std::string, std::pair<std::string, bool>> def;
std::string dfs(std::string s) {
std::string r;
for (int i = 0, j; i < s.size(); i += j) {
for (j = 0; i + j < s.size() &&
('0' <= s[i + j] && s[i + j] <= '9' ||
'a' <= s[i + j] && s[i + j] <= 'z' ||
'A' <= s[i + j] && s[i + j] <= 'Z' || s[i + j] == '_');
j++)
;
if (j) {
std::string tmp = s.substr(i, j), tmp2;
if (def.count(tmp) && !def[tmp].second) {
def[tmp].second = true;
r += dfs(def[tmp].first);
def[tmp].second = false;
} else {
r += tmp;
}
} else {
r += s[i++];
}
}
return r;
}
int main() {
cin >> n;
for (int i = 0; i <= n; i++) {
std::getline(cin, s[i]);
}
for (int i = 1; i <= n; i++) {
if (s[i][0] == '#') {
if (s[i].substr(1, 6) == "define") {
int p = s[i].find_first_of(' ', 8);
std::string name = s[i].substr(8, p - 8),
content = s[i].substr(p + 1);
def[name] = std::make_pair(content, false);
} else { // s[i].substr(1, 6) == "undef"
std::string name = s[i].substr(7);
def.erase(name);
}
cout << endl;
} else {
cout << dfs(s[i]) << endl;
}
}
return 0;
}

BIN
UniversalOJ/734/data/ex_preprocessor1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/ex_preprocessor1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/ex_preprocessor2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/ex_preprocessor2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
UniversalOJ/734/data/preprocessor9.in (Stored with Git LFS) Normal file

Binary file not shown.