This commit is contained in:
2025-05-03 01:36:24 +03:00
parent 96b0571d30
commit f7c107b877
3 changed files with 3 additions and 143 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# Check if the correct number of arguments are provided # Compile and run as in unicorn
if [ "$#" -ne 2 ]; then if [ "$#" -ne 2 ]; then
echo "Usage: $0 <cpp_file> <argument>" echo "Usage: $0 <cpp_file> <argument>"
exit 1 exit 1
@@ -13,7 +14,7 @@ ARGUMENT=$2
clang-format -i -style=file "$CPP_FILE" clang-format -i -style=file "$CPP_FILE"
# Compile the C++ file # Compile the C++ file
g++ "$CPP_FILE" -o run g++ "$CPP_FILE" -o run -O2 -Wall -Werror -std=gnu++23 -lm
# Check if the compilation was successful # Check if the compilation was successful
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
-38
View File
@@ -1,38 +0,0 @@
#include <vector>
#include <iostream>
#include <algorithm>
template <typename I, typename F>
I separate(I beg, I end, F pred) {
auto tmp = beg;
while (tmp != end) {
std::cout << *tmp << std::endl;
++tmp;
}
auto r = remove_if(beg, end, pred);
tmp = beg;
while (tmp != end) {
std::cout << *tmp << std::endl;
++tmp;
}
std::cout << "meow" << std::endl;
return r;
}
int main() {
std::vector v{ 1, -2, 3, -4, 5, -6 };
auto r = separate(v.begin(), v.end(), [](auto x) { return x >= 0; });
// std::cout << std::distance(v.begin(), r) << std::endl << std::endl;
for (auto& item : v) {
std::cout << item << std::endl;
}
return 0;
}
-103
View File
@@ -1,103 +0,0 @@
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
enum TokenKind
{
T_EOF, // end of input stream
T_NUMBER, // int64 number
T_ID, // identifier
K_ALG,
K_ARG,
K_RES,
K_NACH,
K_KON,
K_TSEL,
K_VESHCH,
K_SIM,
K_LIT,
K_LOG,
K_TAB,
K_NTS,
K_KTS,
K_DLIN,
K_DANO,
K_NADO,
K_ESLI,
K_TO,
K_INACHE,
K_VSE,
K_POKA,
K_DLYA,
K_OT,
K_DO,
K_ZNACH,
K_I,
K_ILI,
K_NE,
K_DA,
K_NET,
K_PRI,
K_VYBOR,
K_VVOD,
K_VYVOD,
K_UTV,
T_SEMICOLON,
T_COMMA,
T_ASSIGN,
T_LBR,
T_RBR,
T_LSQBR,
T_RSQBR,
T_PLUS,
T_MINUS,
T_MUL,
T_DIV,
T_EQ,
T_NE,
T_GT,
T_GE,
T_LT,
T_LE
};
const std::string tokens[] =
{
"", // EOF
"", // NUMBER
"", // ID
"алг", "арг", "рез", "нач", "кон", "цел", "вещ", "сим", "лит", "лог",
"таб", "нц", "кц", "длин", "дано", "надо", "если", "то", "иначе", "все",
"пока", "для", "от", "до", "знач", "и", "или", "не", "да", "нет",
"при", "выбор", "ввод", "вывод", "утв",
";", ",", ":=", "(", ")", "[", "]", "+", "-", "*",
"/", "=", "!=", ">", ">=", "<", "<=",
};
int main() {
// строим словарь соответствий
std::map<std::string, TokenKind> mp;
int tmp = 0;
for (auto& wd : tokens) {
mp[wd] = TokenKind(tmp++);
}
std::vector<std::pair<TokenKind, std::string>> v;
for (auto& h : mp) {
v.push_back(std::make_pair(h.second, h.first));
}
std::sort(v.begin(), v.end());
int n = 0;
for (auto& h : v) {
std::cout << h.first << " <=> " << h.second << "\t";
if (!(n++ % 4)) {
std::cout << std::endl;
}
}
return 0;
}