diff --git a/.gitignore b/.gitignore index b03c889..e7d942b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ -*/prog *\~ +**/.o +.nextcloudsync.log +.sync* +**/lectures#/ +wayland/ +procxmos/ + diff --git a/infolabs/assembly/main.c b/1Y-1H/infolabs/assembly/main.c similarity index 100% rename from infolabs/assembly/main.c rename to 1Y-1H/infolabs/assembly/main.c diff --git a/infolabs/assembly/report.md b/1Y-1H/infolabs/assembly/report.md similarity index 100% rename from infolabs/assembly/report.md rename to 1Y-1H/infolabs/assembly/report.md diff --git a/infolabs/assembly/Отчёт по информатике на тему Генерация и анализ ассемблерного кода программы на Си под разные архитектуры.pdf b/1Y-1H/infolabs/assembly/Отчёт по информатике на тему Генерация и анализ ассемблерного кода программы на Си под разные архитектуры.pdf similarity index 100% rename from infolabs/assembly/Отчёт по информатике на тему Генерация и анализ ассемблерного кода программы на Си под разные архитектуры.pdf rename to 1Y-1H/infolabs/assembly/Отчёт по информатике на тему Генерация и анализ ассемблерного кода программы на Си под разные архитектуры.pdf diff --git a/infolabs/assembly/Работа_по_генерации_и_анализу_ассемблерного_кода_программы.pdf b/1Y-1H/infolabs/assembly/Работа_по_генерации_и_анализу_ассемблерного_кода_программы.pdf similarity index 100% rename from infolabs/assembly/Работа_по_генерации_и_анализу_ассемблерного_кода_программы.pdf rename to 1Y-1H/infolabs/assembly/Работа_по_генерации_и_анализу_ассемблерного_кода_программы.pdf diff --git a/infolabs/modelingfonneiman/code.c b/1Y-1H/infolabs/modelingfonneiman/code.c similarity index 100% rename from infolabs/modelingfonneiman/code.c rename to 1Y-1H/infolabs/modelingfonneiman/code.c diff --git a/infolabs/modelingfonneiman/Отчёт по информатике на тему архитектуры фон Неймана.pdf b/1Y-1H/infolabs/modelingfonneiman/Отчёт по информатике на тему архитектуры фон Неймана.pdf similarity index 100% rename from infolabs/modelingfonneiman/Отчёт по информатике на тему архитектуры фон Неймана.pdf rename to 1Y-1H/infolabs/modelingfonneiman/Отчёт по информатике на тему архитектуры фон Неймана.pdf diff --git a/infolabs/modelingfonneiman/Работа по архитектуре фон Неймана (2 недели).pdf b/1Y-1H/infolabs/modelingfonneiman/Работа по архитектуре фон Неймана (2 недели).pdf similarity index 100% rename from infolabs/modelingfonneiman/Работа по архитектуре фон Неймана (2 недели).pdf rename to 1Y-1H/infolabs/modelingfonneiman/Работа по архитектуре фон Неймана (2 недели).pdf diff --git a/infolabs/procmemorylearning/code.c b/1Y-1H/infolabs/procmemorylearning/code.c similarity index 100% rename from infolabs/procmemorylearning/code.c rename to 1Y-1H/infolabs/procmemorylearning/code.c diff --git a/infolabs/procmemorylearning/homecpu.txt b/1Y-1H/infolabs/procmemorylearning/homecpu.txt similarity index 100% rename from infolabs/procmemorylearning/homecpu.txt rename to 1Y-1H/infolabs/procmemorylearning/homecpu.txt diff --git a/infolabs/procmemorylearning/questions.md b/1Y-1H/infolabs/procmemorylearning/questions.md similarity index 100% rename from infolabs/procmemorylearning/questions.md rename to 1Y-1H/infolabs/procmemorylearning/questions.md diff --git a/infolabs/procmemorylearning/run.sh b/1Y-1H/infolabs/procmemorylearning/run.sh similarity index 100% rename from infolabs/procmemorylearning/run.sh rename to 1Y-1H/infolabs/procmemorylearning/run.sh diff --git a/infolabs/procmemorylearning/Отчёт_по_информатике_на_тему_Иерархии_памяти,_работы_процессора.pdf b/1Y-1H/infolabs/procmemorylearning/Отчёт_по_информатике_на_тему_Иерархии_памяти,_работы_процессора.pdf similarity index 100% rename from infolabs/procmemorylearning/Отчёт_по_информатике_на_тему_Иерархии_памяти,_работы_процессора.pdf rename to 1Y-1H/infolabs/procmemorylearning/Отчёт_по_информатике_на_тему_Иерархии_памяти,_работы_процессора.pdf diff --git a/infolabs/procmemorylearning/Работа_по_иерархии_памяти,_процессор_в_ЭВМ_2_недели.pdf b/1Y-1H/infolabs/procmemorylearning/Работа_по_иерархии_памяти,_процессор_в_ЭВМ_2_недели.pdf similarity index 100% rename from infolabs/procmemorylearning/Работа_по_иерархии_памяти,_процессор_в_ЭВМ_2_недели.pdf rename to 1Y-1H/infolabs/procmemorylearning/Работа_по_иерархии_памяти,_процессор_в_ЭВМ_2_недели.pdf diff --git a/1Y-1H/infolabs/pythontrabscribe/input/test.num b/1Y-1H/infolabs/pythontrabscribe/input/test.num new file mode 100755 index 0000000..60d3b2f --- /dev/null +++ b/1Y-1H/infolabs/pythontrabscribe/input/test.num @@ -0,0 +1 @@ +15 diff --git a/1Y-1H/infolabs/pythontrabscribe/input/test.py b/1Y-1H/infolabs/pythontrabscribe/input/test.py new file mode 100755 index 0000000..79f41af --- /dev/null +++ b/1Y-1H/infolabs/pythontrabscribe/input/test.py @@ -0,0 +1,22 @@ +global_var = 10 +neg_num = -5 +result = global_var + neg_num + +user_age = int(input()) + +if global_var >= 5: + result = result + 1 + +if neg_num <= 0: + print("Negatine num\n") + +counter = 0 +while counter <= 3: + print(counter) + counter += 1 + +for i in range(10): + result = result + 1 + +print(result) +print(user_age) diff --git a/1Y-1H/infolabs/pythontrabscribe/main.bak.c b/1Y-1H/infolabs/pythontrabscribe/main.bak.c new file mode 100755 index 0000000..7c5f842 --- /dev/null +++ b/1Y-1H/infolabs/pythontrabscribe/main.bak.c @@ -0,0 +1,317 @@ +#include +#include +#include + +#define MAXINPUTARRAY 1000 +#define MAXKNOWN 30 +#define MAXROW 40 +#define CMDLIST 4 +#define CMDCOUNT 6 + +int it_is_what(wchar_t ch); + +int main(){ + setlocale(LC_ALL, ""); + wchar_t massive[MAXINPUTARRAY] = {0}; + wchar_t knownint[MAXKNOWN] = {0}; + int CellsInMainArray = 0; + + { // GET ALL INPUT + wchar_t ch; + while((ch = getwchar()) != WEOF){ + massive[CellsInMainArray]=ch; + CellsInMainArray++; + if(CellsInMainArray>=MAXINPUTARRAY) + return 1100; + } + } + + { // IS X(LETTER) EXISIST? + int k = 0; + while(k++ < CellsInMainArray){ + if((massive[k] >= 'a' && massive[k] <= 'z') && + massive[k+1]==' ' && + !(massive[k-1] >= 'a' && massive[k-1] <= 'z')){ + int mark = 1; + for(int i = 0;iMAXINPUTARRAY)return 0; + } + + { // TEST FOR COMMENT AND \t \n ' ' + { + if(row[0]=='#'){ + int i = 0; + putwchar('/');putwchar('/'); + while(i++ < rowCursor)putwchar(row[i]); + putwchar('\n'); + continue; + } + } + { + int i = 0; + if(row[0] == WEOF) return 0; + if(rowCursor<4){ + while(i < rowCursor) putwchar(row[i++]); + continue;} + } + { + while(row[0]=='\t' || row[0] == ' '){ + putwchar(row[0]); + for(int i = 0;i 0: + { // PRINT PRE LETTERS + wchar_t word[] = L"if("; + int i = 0; + while(word[i]!='\0')putwchar(word[i++]); + } + { // IF FUNC + int xpos = 3; + putwchar(row[xpos]);// x + putwchar(row[xpos+2]);// > + + // >= + int tmp = 0; + if(it_is_what(row[xpos+3])==8){putwchar(row[xpos+3]);tmp++;} + + // NUM + for(int i = xpos+4+tmp;i 0) + + case 2:{ // WHILE while i < 10: + { // PRINT PRE LETTERS + wchar_t word[] = L"while("; + int i = 0; + while(word[i]!='\0')putwchar(word[i++]); + } + { // WHILE FUNC + int xpos = 6; + putwchar(row[xpos]);// i + putwchar(row[xpos+2]);// > + + // >= + int tmp = 0; + if(it_is_what(row[xpos+3])==8){putwchar(row[xpos+3]);tmp++;} + + // NUM + for(int i = xpos+4+tmp;i='a'&&ch<='z')return 0; + if(ch>='A'&&ch<='Z')return 1; + if(ch>='0'&&ch<='9')return 2; + + if(ch == '=' || ch == '>' || ch == '<' || ch == '!')return 8; + if(ch == '*' || ch == '-' || ch == '+' || ch == '/')return 9; + + + if(ch == '\\' || ch == '\"' || ch == '\'')return 11; + if(ch == '%')return 12; + + return -1; +} diff --git a/1Y-1H/infolabs/pythontrabscribe/main.c b/1Y-1H/infolabs/pythontrabscribe/main.c new file mode 100755 index 0000000..8e64d34 --- /dev/null +++ b/1Y-1H/infolabs/pythontrabscribe/main.c @@ -0,0 +1,373 @@ +#include +#include +#include + +#define MAXINPUTARRAY 1000 +#define MAXKNOWN 30 +#define MAXKNOWNSYMB 32 +#define MAXROW 80 +#define CMDLIST 4 + +// --- GLOBAL DATA --- +wchar_t G_knownint[MAXKNOWN][MAXKNOWNSYMB] = {0}; +int G_knownCount = 0; + +// --- FUNCTION DECLARATIONS --- +int it_is_what(wchar_t ch); +int are_strings_equal(const wchar_t *s1, const wchar_t *s2); +int is_variable_known(const wchar_t *name); +void put_wchar_string(const wchar_t *s); +void put_char_string(const char *s); + + +// --- MAIN TRANSLATOR LOGIC --- +int main() { + setlocale(LC_ALL, ""); + + wchar_t massive[MAXINPUTARRAY] = {0}; + int CellsInMainArray = 0; + + { // GET INPUT + wchar_t ch; + while ((ch = getwchar()) != WEOF) { + if (CellsInMainArray >= MAXINPUTARRAY) { return 1001; } + massive[CellsInMainArray++] = ch; + } + } + + { // PRE-SCAN: DECLARE ALL VARIABLES AS INT + put_char_string("#include \n"); + put_char_string("int main(){\n"); + + int k = 0; + while (k < CellsInMainArray) { + if (it_is_what(massive[k]) == 0 || it_is_what(massive[k]) == 1) { + wchar_t tempName[MAXKNOWNSYMB] = {0}; + int len = 0; + int startK = k; + + { // EXTRACT NAME + while (startK < CellsInMainArray && (it_is_what(massive[startK]) >= 0)) { + if (len < MAXKNOWNSYMB - 1) tempName[len++] = massive[startK]; + startK++; + } + } + + { // CHECK KEYWORDS AND DECLARE + int isKeyword = 0; + if (are_strings_equal(tempName, L"if") || are_strings_equal(tempName, L"while") || + are_strings_equal(tempName, L"for") || are_strings_equal(tempName, L"print") || + are_strings_equal(tempName, L"in") || are_strings_equal(tempName, L"range") || + are_strings_equal(tempName, L"int") || are_strings_equal(tempName, L"input")) isKeyword = 1; + + if (!isKeyword && tempName[0] != L'\0') { + if (!is_variable_known(tempName) && G_knownCount < MAXKNOWN) { + for (int c = 0; c < len; c++) G_knownint[G_knownCount][c] = tempName[c]; + G_knownCount++; + + // DECLARE VARIABLE + put_char_string("int "); + put_wchar_string(tempName); + put_char_string(" = 0;\n"); + } + } + } + k = startK; + } else { + k++; + } + } + putwchar(L'\n'); + } + + // --- SECOND PASS: LEXICAL ANALYSIS AND TRANSLATION --- + int massiveCursor = 0; + wchar_t row[MAXROW] = {0}; + int deathMark = 1; + int blockLevel = 0; + + do { + if (massiveCursor >= CellsInMainArray) break; + + int command = 0; + int rowCursor = 0; + int initialSpaceCount = 0; + + { // GET ROW AND INDENTATION + for (int i = 0; i < MAXROW; i++) row[i] = 0; + rowCursor = 0; + + while (massiveCursor < CellsInMainArray && rowCursor < MAXROW - 1) { + wchar_t cur = massive[massiveCursor]; + if (cur == L'\n') { massiveCursor++; break; } + if (cur == WEOF || massiveCursor == CellsInMainArray - 1) { deathMark = 0; } + row[rowCursor++] = cur; + massiveCursor++; + } + + int i = 0; + while (row[i] == L' ' || row[i] == L'\t') { initialSpaceCount++; i++; } + + // CLOSE BLOCK + if (blockLevel == 1 && initialSpaceCount == 0 && rowCursor > 0) { + put_char_string("}\n"); + blockLevel = 0; + } + + // PRINT INDENTATION + for (int j = 0; j < initialSpaceCount; j++) putwchar(L' '); + + // TRIM ROW + if (initialSpaceCount > 0) { + for (int j = 0; j < rowCursor - initialSpaceCount; j++) { + row[j] = row[j + initialSpaceCount]; + } + rowCursor -= initialSpaceCount; + for (int j = rowCursor; j < MAXROW; j++) row[j] = 0; + } + } + + { // HANDLE PYTHON COMMENTS (#) + int hashPos = -1; + for (int i = 0; i < rowCursor; i++) { + if (row[i] == L'#') { hashPos = i; break; } + } + if (hashPos != -1) { + put_char_string("//"); + for (int k = 0; k < rowCursor; k++) { + if (row[k] == L'#') break; + putwchar(row[k]); + } + for (int k = hashPos + 1; k < rowCursor; k++) putwchar(row[k]); + putwchar(L'\n'); + continue; + } + } + + // SKIP EMPTY LINES + if (rowCursor == 0) { + putwchar(L'\n'); + continue; + } + + { // DETERMINE COMMAND TYPE + wchar_t cmd_list[CMDLIST][10] = {L"if", L"while", L"for", L"print"}; + for (int i = 0; i < CMDLIST; i++) { + int lenCmd = 0; + while (cmd_list[i][lenCmd] != L'\0') lenCmd++; + + if (rowCursor >= lenCmd) { + int match = 1; + for (int k = 0; k < lenCmd; k++) { + if (row[k] != cmd_list[i][k]) { match = 0; break; } + } + + if (match) { + int pos = lenCmd; + while(row[pos] == L' ') pos++; + + if (i == 3) { // PRINT + if (row[pos] == L'(') { command = 4; break; } + } else { // IF, WHILE, FOR + int colonPos = -1; + for (int p = pos; p < rowCursor; p++) { + if (row[p] == L':') { colonPos = p; break; } + } + if (colonPos != -1) { command = i + 1; break; } + } + } + } + } + } + + { // HANDLE ASSIGNMENT / OPERATION (command == 0) + if (command == 0) { + int eqPos = -1; + int plusEqPos = -1; + int varNameEnd = -1; + + for (int i = 0; i < rowCursor; i++) { + if (row[i] == L'=') { + eqPos = i; + if (i > 0 && row[i - 1] == L'+') plusEqPos = i; + varNameEnd = i - 1; + while(varNameEnd >= 0 && row[varNameEnd] == L' ') varNameEnd--; + break; + } + } + + // If assignment found and not comparison + if (eqPos > 0 && row[eqPos + 1] != L'=' && plusEqPos == -1) { + + // 1. Check for input pattern + wchar_t inputPattern[] = L"int(input())"; + int isInput = 1; + int checkIdx = 0; + int valPos = eqPos + 1; + while (row[valPos] == L' ') valPos++; + + while (inputPattern[checkIdx] != L'\0') { + if (row[valPos + checkIdx] != inputPattern[checkIdx]) { isInput = 0; break; } + checkIdx++; + } + + if (isInput) { + // INPUT (scanf) + put_char_string("scanf(\"%d\", &"); + for (int j = 0; j <= varNameEnd; j++) putwchar(row[j]); + put_char_string(");\n"); + } else { + // REGULAR ASSIGNMENT (x = -5, x = a + 1) + for (int i = 0; i < rowCursor; i++) { putwchar(row[i]); } + put_char_string(";\n"); + } + continue; + } + + // Augmented Assignment (x += 1) or other unknown lines + for (int i = 0; i < rowCursor; i++) { putwchar(row[i]); } + put_char_string(";\n"); + continue; + } + } + + { // TRANSLATE COMMAND (switch) + switch (command) { + case 1: // IF + case 2: // WHILE + case 3: { // FOR + wchar_t *start_word; + int len_cmd; + if (command == 1) { start_word = L"if("; len_cmd = 2; } + else if (command == 2) { start_word = L"while("; len_cmd = 5; } + else { start_word = L"for("; len_cmd = 3; } + + put_wchar_string(start_word); + int pos = len_cmd; + while (row[pos] == L' ') pos++; + + if (command == 3) { // FOR (i in range(10)) + wchar_t iterVar[MAXKNOWNSYMB] = {0}; + int ivLen = 0; + + // GET ITERATOR NAME + while (row[pos] != L' ' && row[pos] != L'\0' && pos < rowCursor && row[pos] != L':') { + iterVar[ivLen++] = row[pos]; + pos++; + } + // SKIP 'in range' + while (pos < rowCursor && row[pos] != L'(') pos++; + pos++; + + // C FORMAT: for(i = 0; i < limit; i++) + put_wchar_string(iterVar); put_char_string(" = 0;"); + put_wchar_string(iterVar); put_char_string(" < "); + + // GET LIMIT + while (pos < rowCursor && row[pos] != L')' && row[pos] != L':') { putwchar(row[pos++]); } + + put_char_string(";"); + put_wchar_string(iterVar); put_char_string("++"); + + } else { + // IF / WHILE CONDITION (Handling x >= y conditions) + while (pos < rowCursor && row[pos] != L':') { + if (row[pos] == L'>' && row[pos+1] == L'=') { + put_char_string(" >= "); + pos += 2; + } else if (row[pos] == L'<' && row[pos+1] == L'=') { + put_char_string(" <= "); + pos += 2; + } else if (row[pos] == L'!' && row[pos+1] == L'=') { + put_char_string(" != "); + pos += 2; + } else if (row[pos] == L'=' && row[pos+1] == L'=') { + put_char_string(" == "); + pos += 2; + } else { + putwchar(row[pos++]); + } + } + } + + put_char_string(")\n"); + + // OPEN BLOCK + put_char_string("{\n"); + blockLevel = 1; + break; + } + + case 4: { // PRINT (print(x) or print("hello")) + put_char_string("printf("); + int pos = 5; + while (row[pos] != L'(') pos++; + pos++; + + int isString = (row[pos] == L'\"'); + + if (isString) { + putwchar(L'\"'); + pos++; + while (pos < rowCursor && row[pos] != L')') { + if (row[pos] == L'\"' && isString) break; + putwchar(row[pos++]); + } + putwchar(L'\"'); + } else { + put_char_string("\"%d\", "); + while (pos < rowCursor && row[pos] != L')') { + putwchar(row[pos++]); + } + } + put_char_string(");\n"); + break; + } + } + } + } while (deathMark); + + { // FINAL BRACKETS + if (blockLevel == 1) { + put_char_string("}\n"); + } + put_char_string("}\n"); + } + + return 0; +} + + +// --- AUXILIARY FUNCTION DEFINITIONS --- +void put_wchar_string(const wchar_t *s) { + int i = 0; + while (s[i] != L'\0') { putwchar(s[i++]); } +} +void put_char_string(const char *s) { + int i = 0; + while (s[i] != '\0') { putwchar(s[i++]); } +} +int it_is_what(wchar_t ch) { + if (ch >= L'a' && ch <= L'z') return 0; + if (ch >= L'A' && ch <= L'Z') return 1; + if (ch >= L'0' && ch <= L'9') return 2; + if (ch == L'_') return 3; + return -1; +} +int are_strings_equal(const wchar_t *s1, const wchar_t *s2) { + int i = 0; + while (s1[i] != L'\0' || s2[i] != L'\0') { + if (s1[i] != s2[i]) return 0; + i++; + } + return 1; +} +int is_variable_known(const wchar_t *name) { + if (name[0] == L'\0') return 1; + for (int r = 0; r < G_knownCount; r++) { + if (are_strings_equal(G_knownint[r], name)) { + return 1; + } + } + return 0; +} diff --git a/1Y-1H/infolabs/pythontrabscribe/output/output b/1Y-1H/infolabs/pythontrabscribe/output/output new file mode 100755 index 0000000..1008300 Binary files /dev/null and b/1Y-1H/infolabs/pythontrabscribe/output/output differ diff --git a/1Y-1H/infolabs/pythontrabscribe/output/output.c b/1Y-1H/infolabs/pythontrabscribe/output/output.c new file mode 100755 index 0000000..23649a7 --- /dev/null +++ b/1Y-1H/infolabs/pythontrabscribe/output/output.c @@ -0,0 +1,43 @@ +#include +int main(){ +int global_var = 0; +int neg_num = 0; +int result = 0; +int user_age = 0; +int Negatine = 0; +int num = 0; +int n = 0; +int counter = 0; +int i = 0; + +global_var = 10 ; +neg_num = -5 ; +result = global_var + neg_num ; + +scanf("%d", &user_age); + +if(global_var >= 5) +{ + result = result + 1; + +} +if(neg_num <= 0) +{ + printf("Negatine num\n"); + +} +counter = 0; +while(counter <= 3) +{ + printf("%d", counter); + counter += 1; + +} +for(i = 0;i < 10;i++) +{ + result = result + 1 ; + +} +printf("%d", result); +printf("%d", user_age); +} diff --git a/1Y-1H/infolabs/pythontrabscribe/output/prog b/1Y-1H/infolabs/pythontrabscribe/output/prog new file mode 100755 index 0000000..3c71364 Binary files /dev/null and b/1Y-1H/infolabs/pythontrabscribe/output/prog differ diff --git a/1Y-1H/infolabs/pythontrabscribe/run.sh b/1Y-1H/infolabs/pythontrabscribe/run.sh new file mode 100755 index 0000000..529559f --- /dev/null +++ b/1Y-1H/infolabs/pythontrabscribe/run.sh @@ -0,0 +1,5 @@ +gcc ./main.c -o ./output/prog +./output/prog < ./input/test.py > output/output.c +bat ./output/output.c +gcc ./output/output.c -o ./output/output +./output/output < ./input/test.num diff --git a/1Y-1H/infolabs/pythontrabscribe/Отчёт по информатике на тему Реализация простого конвертера с подмножества Python на Си.pdf b/1Y-1H/infolabs/pythontrabscribe/Отчёт по информатике на тему Реализация простого конвертера с подмножества Python на Си.pdf new file mode 100755 index 0000000..c9dd883 Binary files /dev/null and b/1Y-1H/infolabs/pythontrabscribe/Отчёт по информатике на тему Реализация простого конвертера с подмножества Python на Си.pdf differ diff --git a/1Y-1H/infolabs/pythontrabscribe/Работа_реализация_простого_конвертера_с_подмножества_Python_на_Си.pdf b/1Y-1H/infolabs/pythontrabscribe/Работа_реализация_простого_конвертера_с_подмножества_Python_на_Си.pdf new file mode 100755 index 0000000..8b5ba3d Binary files /dev/null and b/1Y-1H/infolabs/pythontrabscribe/Работа_реализация_простого_конвертера_с_подмножества_Python_на_Си.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 1.pdf b/1Y-1H/proglabs/Lectures/Лекция 1.pdf new file mode 100644 index 0000000..f10e589 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 1.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 10.pdf b/1Y-1H/proglabs/Lectures/Лекция 10.pdf new file mode 100644 index 0000000..8ed723a Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 10.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 11.pdf b/1Y-1H/proglabs/Lectures/Лекция 11.pdf new file mode 100644 index 0000000..afeb639 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 11.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 12.pdf b/1Y-1H/proglabs/Lectures/Лекция 12.pdf new file mode 100644 index 0000000..6840785 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 12.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 13.pdf b/1Y-1H/proglabs/Lectures/Лекция 13.pdf new file mode 100644 index 0000000..04bf6c9 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 13.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 2.pdf b/1Y-1H/proglabs/Lectures/Лекция 2.pdf new file mode 100644 index 0000000..e92e826 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 2.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 3.pdf b/1Y-1H/proglabs/Lectures/Лекция 3.pdf new file mode 100644 index 0000000..c5c2fdb Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 3.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 4.pdf b/1Y-1H/proglabs/Lectures/Лекция 4.pdf new file mode 100644 index 0000000..2da692e Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 4.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 5.pdf b/1Y-1H/proglabs/Lectures/Лекция 5.pdf new file mode 100644 index 0000000..5ab6eab Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 5.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 6.pdf b/1Y-1H/proglabs/Lectures/Лекция 6.pdf new file mode 100644 index 0000000..39454cf Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 6.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 7.pdf b/1Y-1H/proglabs/Lectures/Лекция 7.pdf new file mode 100644 index 0000000..7d07e79 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 7.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 8.pdf b/1Y-1H/proglabs/Lectures/Лекция 8.pdf new file mode 100644 index 0000000..a6b45d7 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 8.pdf differ diff --git a/1Y-1H/proglabs/Lectures/Лекция 9.pdf b/1Y-1H/proglabs/Lectures/Лекция 9.pdf new file mode 100644 index 0000000..41ae226 Binary files /dev/null and b/1Y-1H/proglabs/Lectures/Лекция 9.pdf differ diff --git a/1Y-1H/proglabs/exam/main1.c b/1Y-1H/proglabs/exam/main1.c new file mode 100644 index 0000000..16f3aa8 --- /dev/null +++ b/1Y-1H/proglabs/exam/main1.c @@ -0,0 +1,41 @@ +// Разработайте функцию, выполняющую преобразование строки +//с однобайтовым двоичным числом в целое десятичное число. +#include + +int main(){ + char input; + long long int binary = 0; + int decimal = 0; + + // Input + { + printf("Input binary: "); + while((input=getchar())>='0' && input <= '1'){ + binary = (binary * 10) + (input - '0'); + } + + if(input != '\n' && input != EOF && input != 4){ + printf("Err, handle char not a 1 or 0"); + return 1; + } + } + // __ + + // Func + int base = 1;// base = (2**n) + long long int bin = binary; + while (binary) { + int last = binary % 10; + + binary = binary / 10; + + decimal += last * base; + base = base * 2; + } + // __ + + // Output + printf("binary(%lld) = decimal(%d)",bin,decimal); + return 0; + // __ +} diff --git a/1Y-1H/proglabs/exam/tmp.out b/1Y-1H/proglabs/exam/tmp.out new file mode 100755 index 0000000..543756b Binary files /dev/null and b/1Y-1H/proglabs/exam/tmp.out differ diff --git a/proglabs/lab10/compile.sh b/1Y-1H/proglabs/lab10/compile.sh similarity index 100% rename from proglabs/lab10/compile.sh rename to 1Y-1H/proglabs/lab10/compile.sh diff --git a/proglabs/lab10/func.c b/1Y-1H/proglabs/lab10/func.c similarity index 100% rename from proglabs/lab10/func.c rename to 1Y-1H/proglabs/lab10/func.c diff --git a/proglabs/lab10/head.h b/1Y-1H/proglabs/lab10/head.h similarity index 100% rename from proglabs/lab10/head.h rename to 1Y-1H/proglabs/lab10/head.h diff --git a/proglabs/lab10/main.c b/1Y-1H/proglabs/lab10/main.c similarity index 100% rename from proglabs/lab10/main.c rename to 1Y-1H/proglabs/lab10/main.c diff --git a/proglabs/lab10/prog b/1Y-1H/proglabs/lab10/prog similarity index 100% rename from proglabs/lab10/prog rename to 1Y-1H/proglabs/lab10/prog diff --git a/proglabs/lab10/test/AP_19_10_1827.txt b/1Y-1H/proglabs/lab10/test/AP_19_10_1827.txt similarity index 100% rename from proglabs/lab10/test/AP_19_10_1827.txt rename to 1Y-1H/proglabs/lab10/test/AP_19_10_1827.txt diff --git a/1Y-1H/proglabs/lab10/test/output b/1Y-1H/proglabs/lab10/test/output new file mode 100644 index 0000000..498242a --- /dev/null +++ b/1Y-1H/proglabs/lab10/test/output @@ -0,0 +1,11 @@ + + Средняя длинна слова - 2 +Statistic + "Symb" - [ammount] + + "Letters" - [33] + "Digits" - [0] + "\n" - [2] + "\t" - [0] + "space" - [12] + other - [0] \ No newline at end of file diff --git a/proglabs/lab10/test/output.1_3 b/1Y-1H/proglabs/lab10/test/output.1_3 old mode 100644 new mode 100755 similarity index 100% rename from proglabs/lab10/test/output.1_3 rename to 1Y-1H/proglabs/lab10/test/output.1_3 diff --git a/proglabs/lab10/test/output.2_8 b/1Y-1H/proglabs/lab10/test/output.2_8 old mode 100644 new mode 100755 similarity index 100% rename from proglabs/lab10/test/output.2_8 rename to 1Y-1H/proglabs/lab10/test/output.2_8 diff --git a/proglabs/lab10/test/output.3_4 b/1Y-1H/proglabs/lab10/test/output.3_4 old mode 100644 new mode 100755 similarity index 100% rename from proglabs/lab10/test/output.3_4 rename to 1Y-1H/proglabs/lab10/test/output.3_4 diff --git a/proglabs/lab10/test/test.md b/1Y-1H/proglabs/lab10/test/test.md similarity index 100% rename from proglabs/lab10/test/test.md rename to 1Y-1H/proglabs/lab10/test/test.md diff --git a/proglabs/lab10/test/test.sh b/1Y-1H/proglabs/lab10/test/test.sh old mode 100755 new mode 100644 similarity index 100% rename from proglabs/lab10/test/test.sh rename to 1Y-1H/proglabs/lab10/test/test.sh diff --git a/1Y-1H/proglabs/lab11/compile.sh b/1Y-1H/proglabs/lab11/compile.sh new file mode 100755 index 0000000..28cd126 --- /dev/null +++ b/1Y-1H/proglabs/lab11/compile.sh @@ -0,0 +1 @@ +gcc -Wall main.c ./func.c -o prog diff --git a/1Y-1H/proglabs/lab11/data.csv b/1Y-1H/proglabs/lab11/data.csv new file mode 100755 index 0000000..e3878c5 --- /dev/null +++ b/1Y-1H/proglabs/lab11/data.csv @@ -0,0 +1,10 @@ +Denton,Strong,0,6 +Magee,Avila,2,8 +Leilani,Wade,2,1 +Oren,Guerra,4,5 +Nevada,Clayton,4,8 +Halee,Lynn,3,8 +Jocelyn,Knight,4,6 +Patrick,Sullivan,6,6 +Cyrus,Barlow,8,1 +Matthew,Vaughn,7,4 diff --git a/1Y-1H/proglabs/lab11/head.h b/1Y-1H/proglabs/lab11/head.h new file mode 100755 index 0000000..340cae6 --- /dev/null +++ b/1Y-1H/proglabs/lab11/head.h @@ -0,0 +1,35 @@ +#ifndef HEAD +#define HEAD + +// INCLUDE + #include + #include + #include + +// DEFINE + #define MAXSYMB_IN_NAME 15 + #define MAXSYMB_IN_SURNAME 20 + + #define MAXSYMB_IN_CURROW 20 // SHOOD BE >= THAN MAXSYMB* AND CANNOT BE > 255 + + #define MAXSTUDENTS 10 // SHOOD BE > 255 + + + #define clear wchar_t clear[] = L"\n \033[H\033[J \n"; for(int i = 0;clear[i]!='\0';i++)putwchar(clear[i]) + +// FUNC + // === output.c === + void print_menu_main(void); + void print_wich_student(void); + void print_menu_create(char ws); + void print_menu_edit(char ws); + void print_menu_del(char ws); + void print_no_free_space(void); + + // === input.c === + char get_num(void); + void get_row(wchar_t row[]); + + // === logic.c === + +#endif diff --git a/1Y-1H/proglabs/lab11/input.c b/1Y-1H/proglabs/lab11/input.c new file mode 100755 index 0000000..0593cc8 --- /dev/null +++ b/1Y-1H/proglabs/lab11/input.c @@ -0,0 +1,18 @@ +#include "head.h" + +char get_num(void){ + char ws; + do{ + wchar_t ch; ws = 0; + while((ch=getwchar())>='0'&&ch<='9') + ws = (ws*10) + (ch-'0'); + }while(ws==0); + return ws; +} + +void get_row(wchar_t row[]){ + +} + + + diff --git a/1Y-1H/proglabs/lab11/logic.c b/1Y-1H/proglabs/lab11/logic.c new file mode 100644 index 0000000..e69de29 diff --git a/1Y-1H/proglabs/lab11/main.c b/1Y-1H/proglabs/lab11/main.c new file mode 100755 index 0000000..8fc285d --- /dev/null +++ b/1Y-1H/proglabs/lab11/main.c @@ -0,0 +1,92 @@ +#include "head.h" + +int main(void){ + setlocale(LC_ALL, ""); + struct structStudentList{ + wchar_t _name[MAXSYMB_IN_NAME+1]; + wchar_t _surname[MAXSYMB_IN_SURNAME+1]; + char age; + char curse; + }; + + struct structStudentList students[MAXSTUDENTS+1]; + + char count_acc[MAXSTUDENTS+1]; + { + for (int i = 0; i=10?(ws>=100?3:2):1; + char num[3]; + for (int i = 0;i=0;i--){ + putwchar(num[i]); + } + } + + {//Print last part of sentense + wchar_t word2[] = + L" ?\n"; + for(int i = 0;word2[i]!='\0';i++){ + putwchar(word2[i]); + } + } +} + +void print_list(void){ + wchar_t word[] = + L"\t"; + for(int i = 0;word[i]!='\0';i++){ + putwchar(word[i]); + } + +} + diff --git a/proglabs/lab5/1.c b/1Y-1H/proglabs/lab5/1.c similarity index 100% rename from proglabs/lab5/1.c rename to 1Y-1H/proglabs/lab5/1.c diff --git a/proglabs/lab5/10.c b/1Y-1H/proglabs/lab5/10.c similarity index 100% rename from proglabs/lab5/10.c rename to 1Y-1H/proglabs/lab5/10.c diff --git a/proglabs/lab5/11.c b/1Y-1H/proglabs/lab5/11.c similarity index 100% rename from proglabs/lab5/11.c rename to 1Y-1H/proglabs/lab5/11.c diff --git a/proglabs/lab5/12.c b/1Y-1H/proglabs/lab5/12.c similarity index 100% rename from proglabs/lab5/12.c rename to 1Y-1H/proglabs/lab5/12.c diff --git a/proglabs/lab5/13.c b/1Y-1H/proglabs/lab5/13.c similarity index 100% rename from proglabs/lab5/13.c rename to 1Y-1H/proglabs/lab5/13.c diff --git a/proglabs/lab5/14.c b/1Y-1H/proglabs/lab5/14.c similarity index 100% rename from proglabs/lab5/14.c rename to 1Y-1H/proglabs/lab5/14.c diff --git a/proglabs/lab5/15.c b/1Y-1H/proglabs/lab5/15.c similarity index 100% rename from proglabs/lab5/15.c rename to 1Y-1H/proglabs/lab5/15.c diff --git a/proglabs/lab5/16.c b/1Y-1H/proglabs/lab5/16.c similarity index 100% rename from proglabs/lab5/16.c rename to 1Y-1H/proglabs/lab5/16.c diff --git a/proglabs/lab5/17.c b/1Y-1H/proglabs/lab5/17.c similarity index 100% rename from proglabs/lab5/17.c rename to 1Y-1H/proglabs/lab5/17.c diff --git a/proglabs/lab5/18.c b/1Y-1H/proglabs/lab5/18.c similarity index 100% rename from proglabs/lab5/18.c rename to 1Y-1H/proglabs/lab5/18.c diff --git a/proglabs/lab5/2.c b/1Y-1H/proglabs/lab5/2.c similarity index 100% rename from proglabs/lab5/2.c rename to 1Y-1H/proglabs/lab5/2.c diff --git a/proglabs/lab5/3-1.c b/1Y-1H/proglabs/lab5/3-1.c similarity index 100% rename from proglabs/lab5/3-1.c rename to 1Y-1H/proglabs/lab5/3-1.c diff --git a/proglabs/lab5/3-2.c b/1Y-1H/proglabs/lab5/3-2.c similarity index 100% rename from proglabs/lab5/3-2.c rename to 1Y-1H/proglabs/lab5/3-2.c diff --git a/proglabs/lab5/4.c b/1Y-1H/proglabs/lab5/4.c similarity index 100% rename from proglabs/lab5/4.c rename to 1Y-1H/proglabs/lab5/4.c diff --git a/proglabs/lab5/5.c b/1Y-1H/proglabs/lab5/5.c similarity index 100% rename from proglabs/lab5/5.c rename to 1Y-1H/proglabs/lab5/5.c diff --git a/proglabs/lab5/6.c b/1Y-1H/proglabs/lab5/6.c similarity index 100% rename from proglabs/lab5/6.c rename to 1Y-1H/proglabs/lab5/6.c diff --git a/proglabs/lab5/7.c b/1Y-1H/proglabs/lab5/7.c similarity index 100% rename from proglabs/lab5/7.c rename to 1Y-1H/proglabs/lab5/7.c diff --git a/proglabs/lab5/8.c b/1Y-1H/proglabs/lab5/8.c similarity index 100% rename from proglabs/lab5/8.c rename to 1Y-1H/proglabs/lab5/8.c diff --git a/proglabs/lab5/9.c b/1Y-1H/proglabs/lab5/9.c similarity index 100% rename from proglabs/lab5/9.c rename to 1Y-1H/proglabs/lab5/9.c diff --git a/proglabs/lab6/1.c b/1Y-1H/proglabs/lab6/1.c similarity index 100% rename from proglabs/lab6/1.c rename to 1Y-1H/proglabs/lab6/1.c diff --git a/proglabs/lab6/10.c b/1Y-1H/proglabs/lab6/10.c similarity index 100% rename from proglabs/lab6/10.c rename to 1Y-1H/proglabs/lab6/10.c diff --git a/proglabs/lab6/11.c b/1Y-1H/proglabs/lab6/11.c similarity index 100% rename from proglabs/lab6/11.c rename to 1Y-1H/proglabs/lab6/11.c diff --git a/proglabs/lab6/2.c b/1Y-1H/proglabs/lab6/2.c similarity index 100% rename from proglabs/lab6/2.c rename to 1Y-1H/proglabs/lab6/2.c diff --git a/proglabs/lab6/3.c b/1Y-1H/proglabs/lab6/3.c similarity index 100% rename from proglabs/lab6/3.c rename to 1Y-1H/proglabs/lab6/3.c diff --git a/proglabs/lab6/4.c b/1Y-1H/proglabs/lab6/4.c similarity index 100% rename from proglabs/lab6/4.c rename to 1Y-1H/proglabs/lab6/4.c diff --git a/proglabs/lab6/5.c b/1Y-1H/proglabs/lab6/5.c similarity index 100% rename from proglabs/lab6/5.c rename to 1Y-1H/proglabs/lab6/5.c diff --git a/proglabs/lab6/6.c b/1Y-1H/proglabs/lab6/6.c similarity index 100% rename from proglabs/lab6/6.c rename to 1Y-1H/proglabs/lab6/6.c diff --git a/proglabs/lab6/7.c b/1Y-1H/proglabs/lab6/7.c similarity index 100% rename from proglabs/lab6/7.c rename to 1Y-1H/proglabs/lab6/7.c diff --git a/proglabs/lab6/8.c b/1Y-1H/proglabs/lab6/8.c similarity index 100% rename from proglabs/lab6/8.c rename to 1Y-1H/proglabs/lab6/8.c diff --git a/proglabs/lab6/9.c b/1Y-1H/proglabs/lab6/9.c similarity index 100% rename from proglabs/lab6/9.c rename to 1Y-1H/proglabs/lab6/9.c diff --git a/proglabs/lab7/1.c b/1Y-1H/proglabs/lab7/1.c similarity index 100% rename from proglabs/lab7/1.c rename to 1Y-1H/proglabs/lab7/1.c diff --git a/proglabs/lab7/10.c b/1Y-1H/proglabs/lab7/10.c similarity index 100% rename from proglabs/lab7/10.c rename to 1Y-1H/proglabs/lab7/10.c diff --git a/proglabs/lab7/11.c b/1Y-1H/proglabs/lab7/11.c similarity index 100% rename from proglabs/lab7/11.c rename to 1Y-1H/proglabs/lab7/11.c diff --git a/proglabs/lab7/12.c b/1Y-1H/proglabs/lab7/12.c similarity index 100% rename from proglabs/lab7/12.c rename to 1Y-1H/proglabs/lab7/12.c diff --git a/proglabs/lab7/13.c b/1Y-1H/proglabs/lab7/13.c similarity index 100% rename from proglabs/lab7/13.c rename to 1Y-1H/proglabs/lab7/13.c diff --git a/proglabs/lab7/14.c b/1Y-1H/proglabs/lab7/14.c similarity index 100% rename from proglabs/lab7/14.c rename to 1Y-1H/proglabs/lab7/14.c diff --git a/proglabs/lab7/15.c b/1Y-1H/proglabs/lab7/15.c similarity index 100% rename from proglabs/lab7/15.c rename to 1Y-1H/proglabs/lab7/15.c diff --git a/proglabs/lab7/16.c b/1Y-1H/proglabs/lab7/16.c similarity index 100% rename from proglabs/lab7/16.c rename to 1Y-1H/proglabs/lab7/16.c diff --git a/proglabs/lab7/17.c b/1Y-1H/proglabs/lab7/17.c similarity index 100% rename from proglabs/lab7/17.c rename to 1Y-1H/proglabs/lab7/17.c diff --git a/proglabs/lab7/18.c b/1Y-1H/proglabs/lab7/18.c similarity index 100% rename from proglabs/lab7/18.c rename to 1Y-1H/proglabs/lab7/18.c diff --git a/proglabs/lab7/19.c b/1Y-1H/proglabs/lab7/19.c similarity index 100% rename from proglabs/lab7/19.c rename to 1Y-1H/proglabs/lab7/19.c diff --git a/proglabs/lab7/2.c b/1Y-1H/proglabs/lab7/2.c similarity index 100% rename from proglabs/lab7/2.c rename to 1Y-1H/proglabs/lab7/2.c diff --git a/proglabs/lab7/3.c b/1Y-1H/proglabs/lab7/3.c similarity index 100% rename from proglabs/lab7/3.c rename to 1Y-1H/proglabs/lab7/3.c diff --git a/proglabs/lab7/4.c b/1Y-1H/proglabs/lab7/4.c similarity index 100% rename from proglabs/lab7/4.c rename to 1Y-1H/proglabs/lab7/4.c diff --git a/proglabs/lab7/5.c b/1Y-1H/proglabs/lab7/5.c similarity index 100% rename from proglabs/lab7/5.c rename to 1Y-1H/proglabs/lab7/5.c diff --git a/proglabs/lab7/6.c b/1Y-1H/proglabs/lab7/6.c similarity index 100% rename from proglabs/lab7/6.c rename to 1Y-1H/proglabs/lab7/6.c diff --git a/proglabs/lab7/7.c b/1Y-1H/proglabs/lab7/7.c similarity index 100% rename from proglabs/lab7/7.c rename to 1Y-1H/proglabs/lab7/7.c diff --git a/proglabs/lab7/8.c b/1Y-1H/proglabs/lab7/8.c similarity index 100% rename from proglabs/lab7/8.c rename to 1Y-1H/proglabs/lab7/8.c diff --git a/proglabs/lab7/9.c b/1Y-1H/proglabs/lab7/9.c similarity index 100% rename from proglabs/lab7/9.c rename to 1Y-1H/proglabs/lab7/9.c diff --git a/proglabs/lab7/test b/1Y-1H/proglabs/lab7/test similarity index 100% rename from proglabs/lab7/test rename to 1Y-1H/proglabs/lab7/test diff --git a/proglabs/lab8/code.c b/1Y-1H/proglabs/lab8/code.c similarity index 100% rename from proglabs/lab8/code.c rename to 1Y-1H/proglabs/lab8/code.c diff --git a/proglabs/lab8/func/find.c b/1Y-1H/proglabs/lab8/func/find.c similarity index 100% rename from proglabs/lab8/func/find.c rename to 1Y-1H/proglabs/lab8/func/find.c diff --git a/proglabs/lab8/func/func.h b/1Y-1H/proglabs/lab8/func/func.h similarity index 100% rename from proglabs/lab8/func/func.h rename to 1Y-1H/proglabs/lab8/func/func.h diff --git a/proglabs/lab8/func/primfunc.c b/1Y-1H/proglabs/lab8/func/primfunc.c similarity index 100% rename from proglabs/lab8/func/primfunc.c rename to 1Y-1H/proglabs/lab8/func/primfunc.c diff --git a/proglabs/lab8/func/range.c b/1Y-1H/proglabs/lab8/func/range.c similarity index 100% rename from proglabs/lab8/func/range.c rename to 1Y-1H/proglabs/lab8/func/range.c diff --git a/proglabs/lab8/test.txt b/1Y-1H/proglabs/lab8/test.txt similarity index 100% rename from proglabs/lab8/test.txt rename to 1Y-1H/proglabs/lab8/test.txt diff --git a/proglabs/lab9/compile.sh b/1Y-1H/proglabs/lab9/compile.sh similarity index 100% rename from proglabs/lab9/compile.sh rename to 1Y-1H/proglabs/lab9/compile.sh diff --git a/proglabs/lab9/func/func.c b/1Y-1H/proglabs/lab9/func/func.c similarity index 100% rename from proglabs/lab9/func/func.c rename to 1Y-1H/proglabs/lab9/func/func.c diff --git a/proglabs/lab9/func/func.h b/1Y-1H/proglabs/lab9/func/func.h similarity index 100% rename from proglabs/lab9/func/func.h rename to 1Y-1H/proglabs/lab9/func/func.h diff --git a/proglabs/lab9/func/get.c b/1Y-1H/proglabs/lab9/func/get.c similarity index 100% rename from proglabs/lab9/func/get.c rename to 1Y-1H/proglabs/lab9/func/get.c diff --git a/proglabs/lab9/func/massive.c b/1Y-1H/proglabs/lab9/func/massive.c similarity index 100% rename from proglabs/lab9/func/massive.c rename to 1Y-1H/proglabs/lab9/func/massive.c diff --git a/proglabs/lab9/func/menu.c b/1Y-1H/proglabs/lab9/func/menu.c similarity index 100% rename from proglabs/lab9/func/menu.c rename to 1Y-1H/proglabs/lab9/func/menu.c diff --git a/proglabs/lab9/func/special.c b/1Y-1H/proglabs/lab9/func/special.c similarity index 100% rename from proglabs/lab9/func/special.c rename to 1Y-1H/proglabs/lab9/func/special.c diff --git a/proglabs/lab9/main.c b/1Y-1H/proglabs/lab9/main.c similarity index 100% rename from proglabs/lab9/main.c rename to 1Y-1H/proglabs/lab9/main.c diff --git a/proglabs/lab9/prog b/1Y-1H/proglabs/lab9/prog similarity index 100% rename from proglabs/lab9/prog rename to 1Y-1H/proglabs/lab9/prog diff --git a/proglabs/lab9/test/output b/1Y-1H/proglabs/lab9/test/output similarity index 100% rename from proglabs/lab9/test/output rename to 1Y-1H/proglabs/lab9/test/output diff --git a/proglabs/lab9/test/test.md b/1Y-1H/proglabs/lab9/test/test.md similarity index 100% rename from proglabs/lab9/test/test.md rename to 1Y-1H/proglabs/lab9/test/test.md diff --git a/1Y-2H/arr.c b/1Y-2H/arr.c new file mode 100644 index 0000000..4292ac5 --- /dev/null +++ b/1Y-2H/arr.c @@ -0,0 +1,30 @@ +#include +typedef struct{ + char ch; + struct ste{ + int x; + int y; + int z; + }st; +}STR; + +int main(){ + + STR m1; + putchar('a'); //1 + m1.ch = 'A'; + putchar('g'); //2 + (&m1)->ch = 'B'; + putchar('z'); //3 + putchar('z'); //4 + + + STR* m2; + putchar('a');//5 + m2->st.x = 'A'; + putchar('g'); //6 + (&(m2)->st)->x = 'B'; + putchar('z'); //7 + + +} diff --git a/1Y-2H/arr.s b/1Y-2H/arr.s new file mode 100644 index 0000000..0c1458e --- /dev/null +++ b/1Y-2H/arr.s @@ -0,0 +1,14 @@ + call putchar@PLT #1 + movb $65, -32(%rbp) + call putchar@PLT #2 + movb $66, -32(%rbp) + call putchar@PLT #3 + call putchar@PLT #4 + movl $97, %edi + call putchar@PLT #5 + movq -40(%rbp), %rax + movl $65, 4(%rax) + call putchar@PLT #6 + movq -40(%rbp), %rax + movl $66, 4(%rax) + call putchar@PLT #7 diff --git a/1Y-2H/dsa/DSA_book.pdf b/1Y-2H/dsa/DSA_book.pdf new file mode 100644 index 0000000..6504a18 Binary files /dev/null and b/1Y-2H/dsa/DSA_book.pdf differ diff --git a/1Y-2H/dsa/Lectures/lec1.pdf b/1Y-2H/dsa/Lectures/lec1.pdf new file mode 100644 index 0000000..15c8f53 Binary files /dev/null and b/1Y-2H/dsa/Lectures/lec1.pdf differ diff --git a/1Y-2H/dsa/Lectures/lec2.pdf b/1Y-2H/dsa/Lectures/lec2.pdf new file mode 100644 index 0000000..51b4b63 Binary files /dev/null and b/1Y-2H/dsa/Lectures/lec2.pdf differ diff --git a/1Y-2H/dsa/Lectures/lec3.pdf b/1Y-2H/dsa/Lectures/lec3.pdf new file mode 100644 index 0000000..b452e77 Binary files /dev/null and b/1Y-2H/dsa/Lectures/lec3.pdf differ diff --git a/1Y-2H/dsa/Lectures/lec4.pdf b/1Y-2H/dsa/Lectures/lec4.pdf new file mode 100644 index 0000000..78276e8 Binary files /dev/null and b/1Y-2H/dsa/Lectures/lec4.pdf differ diff --git a/1Y-2H/dsa/README.pdf b/1Y-2H/dsa/README.pdf new file mode 100644 index 0000000..7fe948e Binary files /dev/null and b/1Y-2H/dsa/README.pdf differ diff --git a/1Y-2H/dsa/lab1/data/compile.sh b/1Y-2H/dsa/lab1/data/compile.sh new file mode 100755 index 0000000..425bc24 --- /dev/null +++ b/1Y-2H/dsa/lab1/data/compile.sh @@ -0,0 +1 @@ +gcc -O0 -Wall ../main.c ../searchFunc.c ../sortFunc.c -o run diff --git a/1Y-2H/dsa/lab1/data/graph.gp b/1Y-2H/dsa/lab1/data/graph.gp new file mode 100644 index 0000000..6dc9a36 --- /dev/null +++ b/1Y-2H/dsa/lab1/data/graph.gp @@ -0,0 +1,38 @@ +set terminal pngcairo size 800,1000 font "Arial,12" +set output 'result.png' +set encoding utf8 + +set grid xtics ytics ls 1 lc rgb "#bbbbbb" lw 1 dt 2 +set xlabel "Количество элементов в массиве, тыс" offset 0,-1 +set ylabel "Время выполнения, тики процессора" offset 1,0 + +set xtics rotate by 90 right + +set multiplot layout 2,1 + +# График 1: Все алгоритмы (Log Scale) +set title "Общая сложность (Log scale)" +set logscale y 10 +set format y "%.0f" +set key top left box opaque + +set xrange [250:5000] +set xtics 250 + +plot 'table1.dat' using ($1 >= 250000 ? $1/1000 : 1/0):2 with lp pt 9 ps 1 lw 2 lc rgb "red" title "Linear", \ + 'table1.dat' using ($1 >= 250000 ? $1/1000 : 1/0):3 with lp pt 7 ps 1 lw 2 lc rgb "blue" title "Binary", \ + 'table1.dat' using ($1 >= 250000 ? $1/1000 : 1/0):4 with lp pt 5 ps 1 lw 2 lc rgb "#00CC00" title "Exponential" + +# График 2: Binary vs Exponential (Linear Scale) +unset logscale y +set title "Детальное сравнение: Binary vs Exponential" +set format y "%.0f" +set key top left box opaque + +set xrange [5:100] +set xtics 5 + +plot 'table1.dat' using ($1 < 250000 ? $1/1000 : 1/0):3 with lp pt 9 ps 1.5 lw 2 lc rgb "red" title "Binary", \ + 'table1.dat' using ($1 < 250000 ? $1/1000 : 1/0):4 with lp pt 7 ps 1.5 lw 2 lc rgb "blue" title "Exponential" + +unset multiplot diff --git a/1Y-2H/dsa/lab1/data/lab1__search.pdf b/1Y-2H/dsa/lab1/data/lab1__search.pdf new file mode 100644 index 0000000..9e3cf57 Binary files /dev/null and b/1Y-2H/dsa/lab1/data/lab1__search.pdf differ diff --git a/1Y-2H/dsa/lab1/data/result-1.png b/1Y-2H/dsa/lab1/data/result-1.png new file mode 100644 index 0000000..ac13356 Binary files /dev/null and b/1Y-2H/dsa/lab1/data/result-1.png differ diff --git a/1Y-2H/dsa/lab1/data/result.png b/1Y-2H/dsa/lab1/data/result.png new file mode 100644 index 0000000..504e803 Binary files /dev/null and b/1Y-2H/dsa/lab1/data/result.png differ diff --git a/1Y-2H/dsa/lab1/data/run b/1Y-2H/dsa/lab1/data/run new file mode 100755 index 0000000..0ec5400 Binary files /dev/null and b/1Y-2H/dsa/lab1/data/run differ diff --git a/1Y-2H/dsa/lab1/data/table-1.dat b/1Y-2H/dsa/lab1/data/table-1.dat new file mode 100644 index 0000000..f8cc969 --- /dev/null +++ b/1Y-2H/dsa/lab1/data/table-1.dat @@ -0,0 +1,21 @@ +# N Lin Bin Exp +250000 823880.2400 198.8200 68.2200 +500000 1570157.3600 216.7800 69.3600 +750000 2361166.2800 183.3200 58.1800 +1000000 1909412.9200 157.9600 49.6400 +1250000 2337384.9600 169.6600 49.5400 +1500000 3095655.0200 196.0400 58.1400 +1750000 4426487.6800 181.7800 53.0800 +2000000 3904134.1400 159.0000 48.6000 +2250000 4857206.9400 212.6200 57.4800 +2500000 6241745.4400 179.8400 49.7000 +2750000 6862063.1400 161.5600 46.0600 +3000000 5883265.5000 152.4000 42.4000 +3250000 6590400.2800 151.8000 42.3600 +3500000 6930893.2400 153.7000 43.0800 +3750000 7751974.1400 153.4600 45.6400 +4000000 7903715.5400 146.8000 40.0600 +4250000 8012506.1800 164.6200 43.1800 +4500000 10549555.0400 159.1400 44.7000 +4750000 8672377.1800 148.4200 40.3200 +5000000 8648922.8600 134.4800 36.4800 diff --git a/1Y-2H/dsa/lab1/data/table1.dat b/1Y-2H/dsa/lab1/data/table1.dat new file mode 100644 index 0000000..290a007 --- /dev/null +++ b/1Y-2H/dsa/lab1/data/table1.dat @@ -0,0 +1,62 @@ +# N Lin Bin Exp +5000 22792.2892 255.8908 261.4744 +10000 43178.6448 259.4500 362.3964 +15000 63184.8404 308.3112 488.9792 +20000 84523.9740 365.7352 360.4612 +25000 100447.7676 299.9976 323.6196 +30000 117121.9308 307.2840 332.2964 +35000 138012.7064 311.4680 344.4208 +40000 157729.2220 317.0248 370.1704 +45000 176898.9820 479.0876 459.0616 +50000 198925.1288 334.7180 374.3556 +55000 217621.5508 320.3992 354.5284 +60000 238092.1940 330.9048 363.8292 +65000 257089.6136 324.4956 378.4876 +70000 276850.4564 334.7716 396.1016 +75000 296776.6076 341.7612 384.4184 +80000 318149.4224 348.9776 393.2672 +85000 339139.2752 353.1772 403.8052 +90000 360221.4100 347.5952 390.2360 +95000 433178.5312 394.7536 435.9560 +100000 516536.8316 535.5460 623.7092 +105000 838486.9860 686.8348 885.3348 +110000 869442.6728 712.3252 814.9304 +115000 1093581.5848 942.1464 924.4680 +120000 1188837.8268 938.8536 1109.6240 +125000 1215486.4860 906.0784 1037.6880 +130000 1279109.4168 851.2548 935.3868 +135000 1332500.4964 905.4932 992.1744 +140000 1392278.7032 1029.9752 1018.3992 +145000 1437455.5196 1078.2540 1380.1472 +150000 1474982.9704 986.5660 1141.7676 +155000 1502449.9740 896.2012 1024.4216 +160000 1369750.6928 652.8004 763.5956 +165000 878368.1192 436.8840 501.2496 +170000 884453.1924 711.9916 804.5552 +175000 929062.4524 410.8268 468.9312 +180000 870936.0876 847.9028 912.8372 +185000 1338851.9352 881.3660 756.7676 +190000 1145629.2592 619.9500 832.6808 +195000 1246022.2124 707.1592 722.3872 +200000 1367785.1312 839.6192 898.2104 + +250000 1865680.0492 590.7676 599.5552 +500000 2918958.7568 577.7688 660.8012 +750000 4492213.6780 521.1036 563.6296 +1000000 4202512.0244 552.7112 589.8260 +1250000 6587014.2380 717.3448 726.9956 +1500000 6760774.8748 647.8220 659.6692 +1750000 7515443.8320 665.7284 676.1792 +2000000 8801047.4736 695.7312 686.2312 +2250000 9104591.9784 714.4216 745.4064 +2500000 11373685.2396 742.7092 803.2212 +2750000 12049295.3936 780.7432 858.6344 +3000000 13438895.7052 766.2056 806.7704 +3250000 15012072.8648 825.1600 1000.3176 +3500000 17754709.9804 811.4068 826.6624 +3750000 18787348.3096 2002.7008 2118.2368 +4000000 18870374.2036 1052.3220 1144.2540 +4250000 16816836.3428 833.3472 1097.5500 +4500000 17317340.9908 1073.3676 1377.1500 +4750000 18436313.1016 829.5996 1089.8952 +5000000 19069453.1036 866.5192 1103.5064 diff --git a/1Y-2H/dsa/lab1/data/table_2.dat b/1Y-2H/dsa/lab1/data/table_2.dat new file mode 100644 index 0000000..af3d00d --- /dev/null +++ b/1Y-2H/dsa/lab1/data/table_2.dat @@ -0,0 +1,22 @@ +# N K Lin Bin Bin+Sort Sort +1000 50 124254661.554 74450.162 790412836.162 790338386.00 +1000 100 212643210.268 99492.594 790437878.594 790338386.00 +1000 150 321858886.378 121279.782 790459665.782 790338386.00 +1000 200 372157001.160 190434.848 790528820.848 790338386.00 +1000 250 442590573.866 191732.842 790530118.842 790338386.00 +1000 300 983880552.716 654958.818 790993344.818 790338386.00 +1000 350 1320350672.720 455389.894 790793775.894 790338386.00 +1000 400 683558396.704 303878.160 790642264.160 790338386.00 +1000 450 606651427.380 342184.150 790680570.150 790338386.00 +1000 500 1131750414.154 1029850.578 791368236.578 790338386.00 +# N K Lin Bin Bin+Sort Sort +5000 200 1589592533.108 262529.994 5428089941.994 5427827412.00 +5000 400 3070542998.388 557485.020 5428384897.020 5427827412.00 +5000 600 4142011455.540 532127.878 5428359539.878 5427827412.00 +5000 800 4417290889.972 1007465.758 5428834877.758 5427827412.00 +5000 1000 5601565339.514 1085845.428 5428913257.428 5427827412.00 +5000 1200 7541889444.504 1211935.880 5429039347.880 5427827412.00 +5000 1400 7214405162.354 1241032.638 5429068444.638 5427827412.00 +5000 1600 7982626036.362 2265340.880 5430092752.880 5427827412.00 +5000 1800 9294569988.752 1304890.234 5429132302.234 5427827412.00 +5000 2000 6834711717.418 1426351.070 5429253763.070 5427827412.00 diff --git a/1Y-2H/dsa/lab1/head.h b/1Y-2H/dsa/lab1/head.h new file mode 100644 index 0000000..ee67337 --- /dev/null +++ b/1Y-2H/dsa/lab1/head.h @@ -0,0 +1,26 @@ +#ifndef HEAD +#define HEAD + +#include +#include +//#include + +#define AVG_TIME_LOOPS 5000 +#define AVG_RAND_MAX 10000000 +#define MILLION 1000000 + +double wtime(); +unsigned long long rdtsc(); +int get_rand(int min, int max); +void fill_rand(int *arr, int n); +void merge_sort(int *arr, int n); + +int linear_Search(int *arr, int n, int key); +int exponential_Search(int *arr, int n, int key); +int binary_Search(int *arr, int n, int key); + +void run_exp1(); +void run_exp2(); + +#endif + diff --git a/1Y-2H/dsa/lab1/main.c b/1Y-2H/dsa/lab1/main.c new file mode 100644 index 0000000..0ce48a2 --- /dev/null +++ b/1Y-2H/dsa/lab1/main.c @@ -0,0 +1,176 @@ +#include "head.h" + +int main(int argc,char **argv) { + srand(rdtsc()); + + if(argc>1){ + switch(argv[1][0]){ + case '1': + run_exp1(); + break; + case '2': + run_exp2(); + break; + case '3': + { + if(!(argv[1][1]>='a'&&argv[1][1]<='z')) return 0; + int key = 1,n = 100; + printf("Write key:"); + scanf("%d",&key); + while(getchar()>'\n'); + printf("Write n:"); + scanf("%d",&n); + while(getchar()>'\n'); + int *arr = (int*)malloc(sizeof(int) * n); + fill_rand(arr, n); + arr[get_rand(0,n)] = key; + merge_sort(arr, n); + for(int i = 0; i +#include +#include +#include + +#define AVG_TIME_LOOPS 1 +#define AVG_RAND_MAX 100000 +#define MILLION 1000000 + +void sort_radix(uint32_t* arr,int n); +void sort_heap(uint32_t* arr,int n); +void sort_bubble(uint32_t* arr,int n); +void sort_merge(uint32_t* arr,int left, int right); + + +void run_exp(); + +#endif + diff --git a/1Y-2H/dsa/lab2/code/main.c b/1Y-2H/dsa/lab2/code/main.c new file mode 100644 index 0000000..1d6020d --- /dev/null +++ b/1Y-2H/dsa/lab2/code/main.c @@ -0,0 +1,126 @@ +#include "head.h" +#include + +double get_time(); +void fill_rand(uint32_t *arr, int n); + +int main(int argc,char **argv) { + srand(get_time()); + + if(argc>1){ + switch(argv[1][0]){ + case '1': // Exp what sort is faster + run_exp(); + break; + case '2': // Test Sorts + { + int n; + if(!(argv[1][1]>='a'&&argv[1][1]<='z')) return 0; + printf("Write n:"); + scanf("%d",&n); + while(getchar()>'\n'); + uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n); + fill_rand(arr, n); + for(int i = 0; i 0; exp *= 10) + counting_sort(arr, n, exp); +} +uint32_t get_max(uint32_t* arr, int n) { + uint32_t max = arr[0]; + for(int i = 1; i < n; i++) + if(arr[i] > max) + max = arr[i]; + return max; +} +void counting_sort(uint32_t* arr, int n, int exp) { + uint32_t output[n]; + uint32_t count[10] = {0}; + + for(int i = 0; i < n; i++) + count[(arr[i] / exp) % 10]++; + + for(int i = 1; i < 10; i++) + count[i] += count[i - 1]; + + for(int i = n - 1; i >= 0; i--) { + output[count[(arr[i] / exp) % 10] - 1] = arr[i]; + count[(arr[i] / exp) % 10]--; + } + + for(int i = 0; i < n; i++) + arr[i] = output[i]; +} +// === === === HEAP SORT === === === +void heapify(uint32_t* arr, int n, int i); +void swap(uint32_t* a, uint32_t *b); +void sort_heap(uint32_t* arr,int n){ + for(int i = n/2 - 1; i >= 0; i--) + heapify(arr, n, i); + + for(int i = n - 1; i > 0; i--) { + swap(&arr[0], &arr[i]); + heapify(arr, i, 0); + } +} +void swap(uint32_t* a, uint32_t *b) { + int temp = *a; + *a = *b; + *b = temp; +} +void heapify(uint32_t* arr, int n, int i) { + int largest = i; + int left = 2 * i + 1; + int right = 2 * i + 2; + + if(left < n && arr[left] > arr[largest]) + largest = left; + + if(right < n && arr[right] > arr[largest]) + largest = right; + + if(largest != i) { + swap(&arr[i], &arr[largest]); + + heapify(arr, n, largest); + } +} + +// === === === BUBBLE SORT === === === +void sort_bubble(uint32_t* arr,int n){ + for(int i = 0; i < n - 1; i++) { + int swapped = 0; + for(int j = 0; j < n - i - 1; j++) { + if(arr[j] > arr[j + 1]) { + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + swapped = 1; + } + } + if(!swapped) break; + } +} + +// === === === MERGE SORT === === === +void merge(uint32_t* arr, int left, int mid, int right); +void sort_merge(uint32_t* arr, int left, int right){ + if(left < right) { + int mid = left + (right - left) / 2; + + sort_merge(arr, left, mid); + sort_merge(arr, mid + 1, right); + merge(arr, left, mid, right); + } +} +void merge(uint32_t* arr, int left, int mid, int right) { + int n1 = mid - left + 1; + int n2 = right - mid; + + int L[n1], R[n2]; + + for(int i = 0; i < n1; i++) + L[i] = arr[left + i]; + for(int j = 0; j < n2; j++) + R[j] = arr[mid + 1 + j]; + + int i = 0, j = 0, k = left; + while(i < n1 && j < n2) { + if(L[i] <= R[j]) { + arr[k] = L[i]; + i++; + } else { + arr[k] = R[j]; + j++; + } + k++; + } + while(i < n1) { arr[k] = L[i]; i++; k++;} + while(j < n2) { arr[k] = R[j]; j++; k++;} +} diff --git a/1Y-2H/dsa/lab2/data/lab2__sort.pdf b/1Y-2H/dsa/lab2/data/lab2__sort.pdf new file mode 100644 index 0000000..d332e1e Binary files /dev/null and b/1Y-2H/dsa/lab2/data/lab2__sort.pdf differ diff --git a/1Y-2H/dsa/lab2/data/makefile b/1Y-2H/dsa/lab2/data/makefile new file mode 100644 index 0000000..e6d42bb --- /dev/null +++ b/1Y-2H/dsa/lab2/data/makefile @@ -0,0 +1,28 @@ +CC = gcc + +CFLAGS = -Wall -Wextra -I../ -g +TARGET = sort + +SRC_DIR = ../code +OBJ_DIR = ../.o + +SRCS = $(wildcard $(SRC_DIR)/*.c) +OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS)) + +.PHONY: all clean run + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(TARGET) + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + @mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) -c $< -o $@ + +run: $(TARGET) + ./$(TARGET) < input > output + @cat output + +clean: + rm -rf $(OBJ_DIR) $(TARGET) output diff --git a/1Y-2H/dsa/lab2/data/sort b/1Y-2H/dsa/lab2/data/sort new file mode 100755 index 0000000..18406cf Binary files /dev/null and b/1Y-2H/dsa/lab2/data/sort differ diff --git a/1Y-2H/dsa/lab2/data/table.dat b/1Y-2H/dsa/lab2/data/table.dat new file mode 100644 index 0000000..e69de29 diff --git a/1Y-2H/dsa/lab4/lab4__BST_hashtable.pdf b/1Y-2H/dsa/lab4/lab4__BST_hashtable.pdf new file mode 100644 index 0000000..44dfc84 Binary files /dev/null and b/1Y-2H/dsa/lab4/lab4__BST_hashtable.pdf differ diff --git a/1Y-2H/dsa/lab5/lab5__heap.pdf b/1Y-2H/dsa/lab5/lab5__heap.pdf new file mode 100644 index 0000000..45b783e Binary files /dev/null and b/1Y-2H/dsa/lab5/lab5__heap.pdf differ diff --git a/1Y-2H/dsa/snippet.c b/1Y-2H/dsa/snippet.c new file mode 100644 index 0000000..32acf13 --- /dev/null +++ b/1Y-2H/dsa/snippet.c @@ -0,0 +1,34 @@ +#include +#include +#include + +double wtime(); +int getrand(int min, int max); +void fill_rand(int *arr, int n); + +int main(void){ + int sn = 50000; + int en = 1000000; + int step = 50000; + srand(123); + + FILE *f = fopen("res.dat", "w"); + + +} + + +double wtime() { + struct timeval t; + gettimeofday(&t, NULL); + return (double)t.tv_sec + (double)t.tv_usec * 1E-6; +} + +int getrand(int min, int max) { + return (double)rand() / (RAND_MAX + 1.0) * (max - min) + min; +} + +void fill_rand(int *arr, int n) { + for (int i = 0; i < n; i++) + arr[i] = getrand(1, 1000001); +} diff --git a/1Y-2H/prog/1Practice/nPractic1.pdf b/1Y-2H/prog/1Practice/nPractic1.pdf new file mode 100644 index 0000000..68d4daf Binary files /dev/null and b/1Y-2H/prog/1Practice/nPractic1.pdf differ diff --git a/1Y-2H/prog/1Practice/var2/code/head.h b/1Y-2H/prog/1Practice/var2/code/head.h new file mode 100644 index 0000000..b7e9731 --- /dev/null +++ b/1Y-2H/prog/1Practice/var2/code/head.h @@ -0,0 +1,48 @@ +#ifndef Head +#define Head + +// INCLUDE + #include + #include + #include + +// DEFINE + #define LLI long long int + #define MAX_MATRIX_ALIVE 21 + #define BUFF_MAX 10 //(char) <= 254 + #define IN_BUFF_CHARS 10 //(char) <= 254 + +//TypeDef + // matrix.c + typedef struct { + int rows; + int cols; + int** data; + } MATRIX2D; + + +// FUNC + // === io.c === + MATRIX2D* create_matrix2d(int rows, int cols); + char buff_input(char *inbuff, char *_buff); + char cmd_buff(char* _buff,char** _charCommands,char NUM_OF_CHAR_COMMANDS); + char get_matrix_num(void); + int get_num(void); + + // === matrix.c === + void create_matrix(MATRIX2D** addr, unsigned char n, int rows, int cols); + void input_matrix(MATRIX2D** addr, unsigned char n); + void get_matrix(MATRIX2D** addr, unsigned char n); + void logic_matrix(MATRIX2D** addr, unsigned char n1, unsigned char n2); + void edit_matrix(MATRIX2D** addr, unsigned char n); + void matrix_random(MATRIX2D** addr, unsigned char n); + void copy_matrix(MATRIX2D** addr, unsigned char n1, unsigned char n2); + void free_matrix(MATRIX2D** addr, unsigned char n); + void get_matrix_col(MATRIX2D** addr, unsigned char n, int c); + void get_matrix_row(MATRIX2D** addr, unsigned char n, int r); + void transp_matrix(MATRIX2D** addr, unsigned char n); + LLI determ_matrix(MATRIX2D** addr, unsigned char n); + void obr_matrix(MATRIX2D** addr, unsigned char n); + void is_Matrix_Exist(MATRIX2D** addr, unsigned char n); + +#endif diff --git a/1Y-2H/prog/1Practice/var2/code/io.c b/1Y-2H/prog/1Practice/var2/code/io.c new file mode 100644 index 0000000..57a21bb --- /dev/null +++ b/1Y-2H/prog/1Practice/var2/code/io.c @@ -0,0 +1,108 @@ +#include "head.h" + +char buff_input(char *inbuff, char *_buff){ + + *inbuff = 0; + { // INPUT + char ch; + while((ch=getchar())>' '&&*inbuff='a' && _buff[0] <= 'z') + { // Is input - command? + const char NUM_OF_CHAR_COMMANDS = 15; + char * _charCommands[NUM_OF_CHAR_COMMANDS]; // _charCommands[*]["char"] + _charCommands[0] = (char[]){"input"}; + _charCommands[1] = (char[]){"getmatrix"}; + _charCommands[2] = (char[]){"logic"}; + _charCommands[3] = (char[]){"edit"}; + _charCommands[4] = (char[]){"random"}; + _charCommands[5] = (char[]){"copy"}; + _charCommands[6] = (char[]){"destruct"}; + _charCommands[7] = (char[]){"getcolum"}; + _charCommands[8] = (char[]){"getrow"}; + _charCommands[9] = (char[]){"transp"}; + _charCommands[10] = (char[]){"determ"}; + _charCommands[11] = (char[]){"obr"}; + _charCommands[12] = (char[]){"create"}; + _charCommands[13] = (char[]){"n"}; + _charCommands[14] = (char[]){"exit"}; + + + char cmd = cmd_buff(_buff,_charCommands,NUM_OF_CHAR_COMMANDS); + if(cmd==15)return -1; //exit + return cmd; //Вернуть комману + } + + return 0; +} + +char cmd_buff(char* _buff,char** _charCommands,char NUM_OF_CHAR_COMMANDS){ + for (int i = 0;i0&&*_buff>' '); + + long int num = 0; + char flagIsDec = 1; + { // GetNum + int i = 0; + if(_buff[0]=='-'){i++;flagIsDec = -1;} + + for(; i= '0' && _buff[i] <= '9') + num = (num*10) + (_buff[i]-'0'); + num *= flagIsDec; + } + if (num>MAX_MATRIX_ALIVE)num = MAX_MATRIX_ALIVE; + if (num<0)num = 0; + return num; +} + + +int get_num(void){ + char inbuff; + char _buff[BUFF_MAX]; + while(buff_input(&inbuff,_buff)>0&&*_buff>' '); + + long int num = 0; + char flagIsDec = 1; + { // GetNum + int i = 0; + if(_buff[0]=='-'){i++;flagIsDec = -1;} + + for(; i= '0' && _buff[i] <= '9') + num = (num*10) + (_buff[i]-'0'); + num *= flagIsDec; + } + if (num>INT_MAX)num = INT_MAX; + if (num=0); + + return 0; +} diff --git a/1Y-2H/prog/1Practice/var2/code/matrix.c b/1Y-2H/prog/1Practice/var2/code/matrix.c new file mode 100644 index 0000000..f065ddd --- /dev/null +++ b/1Y-2H/prog/1Practice/var2/code/matrix.c @@ -0,0 +1,374 @@ +#include "head.h" + +MATRIX2D* create_matrix2d(int rows,int cols) { + MATRIX2D* m = (MATRIX2D*)malloc(sizeof(MATRIX2D)); + m->rows = rows; + m->cols = cols; + + m->data = (int**)malloc(rows * sizeof(int*)); + + for (int i = 0; i < rows; i++){ + m->data[i] = (int*)malloc(cols * sizeof(int)); + } + + return m; +} + +void create_matrix(MATRIX2D** __addr,unsigned char n,int rows,int cols){ + __addr[n] = create_matrix2d(rows,cols); + for (int i = 0;idata[i][j] = 0; + } + } +} + +void input_matrix(MATRIX2D** __addr,unsigned char n){ + int** data = __addr[n]->data; + + for(int rows = 0; rows < __addr[n]->rows;rows++){ + for(int cols = 0; cols < __addr[n]->cols;cols++){ + int num = get_num(); + data[rows][cols] = num; + } + } + } + + void get_matrix(MATRIX2D** __addr,unsigned char n){ + int rows = __addr[n]->rows; + int cols = __addr[n]->cols; + + //printf("\tМассив №%d",n); + //printf("Колл-во строк %d\nКолл-во колон %d\n\n",rows,cols); + for(int r = 0;rdata[r][c]); + } + putchar('\n'); + } +} + +void logic_matrix(MATRIX2D** __addr,unsigned char n1,unsigned char n2){ + char inbuff; + char _buff[BUFF_MAX]; + int** data1 = __addr[n1]->data; + int** data2 = __addr[n2]->data; + + char cmd = 0; + { + buff_input(&inbuff,_buff); + + const char NUM_OF_CHAR_COMMANDS = 6; + char * _charCommands[NUM_OF_CHAR_COMMANDS]; // _charCommands[*]["char"] + _charCommands[0] = (char[]){"=="}; + _charCommands[1] = (char[]){"!="}; + _charCommands[2] = (char[]){">="}; + _charCommands[3] = (char[]){"<="}; + _charCommands[4] = (char[]){">"}; + _charCommands[5] = (char[]){"<"}; + + cmd = cmd_buff(_buff,_charCommands,NUM_OF_CHAR_COMMANDS); + } + + LLI cost1 = 0; + { + for(int r = 0;r<__addr[n1]->rows;r++) + for(int c = 0;c<__addr[n1]->cols;c++) + cost1 += data1[r][c]; + } + LLI cost2 = 0; + { + for(int r = 0;r<__addr[n2]->rows;r++) + for(int c = 0;c<__addr[n2]->cols;c++) + cost2 += data2[r][c]; + } + + switch(cmd){ + case 0: //Null + putchar('-');putchar('1'); + break; + case 1: // == + putchar(cost1==cost2?'1':'0'); + break; + case 2: // != + putchar(cost1!=cost2?'1':'0'); + break; + case 3: //>= + putchar(cost1>=cost2?'1':'0'); + break; + case 4: //<= + putchar(cost1<=cost2?'1':'0'); + break; + case 5: // > + putchar(cost1>cost2?'1':'0'); + break; + case 6: // < + putchar(cost1data; + int r = 0, c = 0; + char mode = 0; + + char* _locStrings[3]; + _locStrings[0] = (char[]){"point"}; + _locStrings[1] = (char[]){"add"}; + _locStrings[2] = (char[]){"sub"}; + + while (r < __addr[n]->rows) { + char res = buff_input(&inbuff, _buff); + if (res == -1) break; + + if (_buff[0] == 'n' && inbuff == 1) break; + + char loc_cmd = cmd_buff(_buff, _locStrings, 3); + + if (loc_cmd == 1) { + buff_input(&inbuff, _buff); + long pr = 0, pc = 0; + int i = 0; + for (; i < inbuff && (_buff[i] != ':' && _buff[i] != ',' && _buff[i] != '.'); i++) + if (_buff[i] >= '0' && _buff[i] <= '9') pr = pr * 10 + (_buff[i] - '0'); + for (i++; i < inbuff; i++) + if (_buff[i] >= '0' && _buff[i] <= '9') pc = pc * 10 + (_buff[i] - '0'); + + if (pr < __addr[n]->rows && pc < __addr[n]->cols) { + r = (int)pr; + c = (int)pc; + } + continue; + } + + if (loc_cmd == 2) { mode = 1; continue; } + if (loc_cmd == 3) { mode = 2; continue; } + + long val = 0; + int i = 0, sign = 1; + if (inbuff > 0 && _buff[0] == '-') { sign = -1; i++; } + for (; i < inbuff; i++) { + if (_buff[i] >= '0' && _buff[i] <= '9') + val = val * 10 + (_buff[i] - '0'); + } + val *= sign; + + if (mode == 1) { + long res_val = (long)data[r][c] + val; + data[r][c] = (res_val > INT_MAX) ? INT_MAX : (res_val < INT_MIN) ? INT_MIN : (int)res_val; + } else if (mode == 2) { + long res_val = (long)data[r][c] - val; + data[r][c] = (res_val > INT_MAX) ? INT_MAX : (res_val < INT_MIN) ? INT_MIN : (int)res_val; + } else { + data[r][c] = (val > INT_MAX) ? INT_MAX : (val < INT_MIN) ? INT_MIN : (int)val; + } + + if (++c >= __addr[n]->cols) { + c = 0; + r++; + } + } +} + +int get_rand(int min, int max) { + return (double)rand() / (RAND_MAX + 1.0) * (max - min) + min; +} + +void matrix_random(MATRIX2D** __addr,unsigned char n){ + unsigned int lo, hi; + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); + srand(((unsigned long long)hi << 32) | lo); + + for (int r = 0; r < __addr[n]->rows; r++){ + for(int c = 0; c < __addr[n]->cols; c++){ + __addr[n]->data[r][c] = get_rand(-100, 100); + } + } +} + +void copy_matrix(MATRIX2D** __addr,unsigned char n1, unsigned char n2){ + // n2 = n1 + __addr[n2] = create_matrix2d(__addr[n1]->rows,__addr[n1]->cols); + + for(int i = 0; i<__addr[n1]->rows;i++){ + for(int j = 0; j<__addr[n1]->cols;j++){ + __addr[n2]->data[i][j] = __addr[n1]->data[i][j]; + } + } +} + +void free_matrix(MATRIX2D** __addr,unsigned char n){ + if (__addr[n] == NULL) return; + + MATRIX2D* m = __addr[n]; + for (int i = 0; i < m->rows; i++) { + free(m->data[i]); + } + free(m->data); + free(m); + + __addr[n] = NULL; +} + +void get_matrix_col(MATRIX2D** __addr,unsigned char n,int c){ + //printf("colum %d - ",c); + if(c >= __addr[n]->cols)c = __addr[n]->cols - 1; + if(c<0)c = 0; + for(int i = 0;i<__addr[n]->rows;i++){ + printf("%d ",__addr[n]->data[i][c]); + } + putchar('\n'); +} + +void get_matrix_row(MATRIX2D** __addr,unsigned char n,int r){ + //printf("row %d - ",r); + if(r >= __addr[n]->rows)r = __addr[n]->rows - 1; + if(r<0)r = 0; + for(int i = 0;i<__addr[n]->cols;i++){ + printf("%d ",__addr[n]->data[r][i]); + } + putchar('\n'); +} + +void transp_matrix(MATRIX2D** __addr,unsigned char n){ + MATRIX2D* tr = create_matrix2d( + __addr[n]->cols,__addr[n]->rows); + + + int** dataDef = __addr[n]->data; + int** dataRes = tr->data; + + for(int r = 0;r<__addr[n]->rows;r++) + for(int c = 0;c<__addr[n]->cols;c++) + dataRes[c][r] = dataDef[r][c]; + + free_matrix(__addr,n); + + __addr[n] = tr; +} + +LLI determ_matrix(MATRIX2D** __addr, unsigned char n) { + int size = __addr[n]->rows; + int** data = __addr[n]->data; + + if (size == 1) return data[0][0]; + if (size == 2) return (LLI)data[0][0] * data[1][1] - (LLI)data[0][1] * data[1][0]; + + double det = 1.0; + double** temp = (double**)malloc(size * sizeof(double*)); + for (int i = 0; i < size; i++) { + temp[i] = (double*)malloc(size * sizeof(double)); + for (int j = 0; j < size; j++) temp[i][j] = (double)data[i][j]; + } + + for (int i = 0; i < size; i++) { + int pivot = i; + for (int j = i + 1; j < size; j++) { + double val1 = temp[j][i] < 0 ? -temp[j][i] : temp[j][i]; + double val2 = temp[pivot][i] < 0 ? -temp[pivot][i] : temp[pivot][i]; + if (val1 > val2) pivot = j; + } + + if (pivot != i) { + double* swap = temp[i]; + temp[i] = temp[pivot]; + temp[pivot] = swap; + det *= -1; + } + + double current_val = temp[i][i] < 0 ? -temp[i][i] : temp[i][i]; + if (current_val < 1e-9) { + for (int k = 0; k < size; k++) free(temp[k]); + free(temp); + return 0; + } + + det *= temp[i][i]; + + for (int j = i + 1; j < size; j++) { + double factor = temp[j][i] / temp[i][i]; + for (int k = i + 1; k < size; k++) { + temp[j][k] -= factor * temp[i][k]; + } + } + } + + LLI final_det; + if (det >= 0) final_det = (LLI)(det + 0.5); + else final_det = (LLI)(det - 0.5); + + for (int i = 0; i < size; i++) free(temp[i]); + free(temp); + + return final_det; +} + +void obr_matrix(MATRIX2D** __addr, unsigned char n) { + int size = __addr[n]->rows; + if (size != __addr[n]->cols) return; + + LLI d = determ_matrix(__addr, n); + if (d == 0) return; + + double** temp = (double**)malloc(size * sizeof(double*)); + for (int i = 0; i < size; i++) { + temp[i] = (double*)malloc(2 * size * sizeof(double)); + for (int j = 0; j < size; j++) { + temp[i][j] = (double)__addr[n]->data[i][j]; + temp[i][j + size] = (i == j ? 1.0 : 0.0); + } + } + + for (int i = 0; i < size; i++) { + int pivot = i; + for (int j = i + 1; j < size; j++) { + double v1 = temp[j][i] < 0 ? -temp[j][i] : temp[j][i]; + double v2 = temp[pivot][i] < 0 ? -temp[pivot][i] : temp[pivot][i]; + if (v1 > v2) pivot = j; + } + + double* row_ptr = temp[i]; + temp[i] = temp[pivot]; + temp[pivot] = row_ptr; + + double divisor = temp[i][i]; + for (int j = i; j < 2 * size; j++) { + temp[i][j] /= divisor; + } + + for (int k = 0; k < size; k++) { + if (k != i) { + double factor = temp[k][i]; + for (int j = i; j < 2 * size; j++) { + temp[k][j] -= factor * temp[i][j]; + } + } + } + } + + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + double val = temp[i][j + size]; + if (val >= 0) __addr[n]->data[i][j] = (int)(val + 0.5); + else __addr[n]->data[i][j] = (int)(val - 0.5); + } + } + + for (int i = 0; i < size; i++) free(temp[i]); + free(temp); +} + +void is_Matrix_Exist(MATRIX2D** __addr,unsigned char n){ + if(n > MAX_MATRIX_ALIVE) n = MAX_MATRIX_ALIVE-1; + if(__addr[n] == NULL){ + //printf("Матрица №%d не существует, создана новая матрица 4x4\n",n); + __addr[n] = create_matrix2d(4,4); + matrix_random(__addr,n); + } + + return; +} + diff --git a/1Y-2H/prog/1Practice/var2/docs.md b/1Y-2H/prog/1Practice/var2/docs.md new file mode 100644 index 0000000..03c3617 --- /dev/null +++ b/1Y-2H/prog/1Practice/var2/docs.md @@ -0,0 +1,111 @@ +## Matrix + +Когда вы запускаете програму она будет ожидать одну из следующих коммнад. +Ввод чисел будет проигнорирован но, адм символы приведут к завершению программы. + +При вводе символов весь ввод является строкой. +Делителем строк являются - Space Enter EOT +Также каждый 10 символ - новая строка +При вводе, каждое запрашиваемое значение должно заканчиваться делителем + +###### Пример: + +create +0 +10 20 +getmatrix +exit + +Номер матрицы ограничен их возможным колличеством установленным в header.h +По умолчанию = 20 + +Если вы пытаетесь манипулировать несуществующей матрицей +То будет создана матрица 4 X 4 со случайными значениями от -100 до 100 + +## + +Далее будет описыватся только ожидаеммый ввод после команды. +Функцианал коммнады понятен из названия. + +#### create + +(Ожидается 3 числа) +номер-матрицы +коллво-строк +коллво-колон + +#### input + +(Ожидается 1 число) +номер-матрицы +(далее будет ввод матрицы X на Y необходимо ввести X\*Y значений) +int1 int2 int3 ... int(x\*y) + +#### getmatrix + +(Ожидается 1 число) +номер-матрицы + +#### logic + +(Ожидается 2 числа) +номер-матрицы1 +номер-матрицы2 +(Ожидается логическая операция > < >= <= != == ) +Логическа-операция + +#### edit + +(Ожидается 1 число) +номер-матрицы +(Далее принимает X\*Y чисел и заменяет предыдущие) +(Так же может принять 3 буквенных выражения, +add - все последующие введёные числа будут добавлены к имеющимся +sub - от всех имеющихся чисел будут отняты последующие введёные +point - указать на точку в массиве начиная с которой продолжить заполнение, row:col для разделения могут использоваться , . :) + + +#### random + +(Ожидается 1 число) +номер-матрицы + +#### copy + +(Ожидается 2 числа) +номер-матрицы-откуда-копировать +номер-матрицы-куда-копировать + +#### destruct + +(Ожидается 1 число) +номер-матрицы + +#### getcolum + +(Ожидается 2 числа) +номер-матрицы +номер-столбца + +#### getrow + +(Ожидается 2 числа) +номер-матрицы +номер-строки + +#### transp + +(Ожидается 1 число) +номер-матрицы + +#### determ + +(Ожидается 1 число) +номер-матрицы + +#### obr + +(Ожидается 1 число) +номер-матрицы + +#### exit diff --git a/1Y-2H/prog/1Practice/var2/run/input b/1Y-2H/prog/1Practice/var2/run/input new file mode 100644 index 0000000..4b4c318 --- /dev/null +++ b/1Y-2H/prog/1Practice/var2/run/input @@ -0,0 +1,38 @@ +create 0 3 3 +input 0 +1 2 3 +4 5 6 +7 8 9 +getmatrix 0 +n n +transp 0 +getmatrix 0 +n n +create 1 3 3 +random 1 +getmatrix 1 +n +logic 0 1 >= n +logic 0 0 == n +edit 0 +add +1 1 1 +1 1 1 +1 1 1 +getmatrix 0 +n +edit 0 +point 1:1 +sub +10 10 +getmatrix 0 +n +getcolum 0 1 +getrow 0 2 +n +copy 0 5 +getmatrix 5 +n +determ 5 +destruct 5 +exit diff --git a/1Y-2H/prog/1Practice/var2/run/makefile b/1Y-2H/prog/1Practice/var2/run/makefile new file mode 100644 index 0000000..c8d07fe --- /dev/null +++ b/1Y-2H/prog/1Practice/var2/run/makefile @@ -0,0 +1,28 @@ +CC = gcc + +CFLAGS = -Wall -Wextra -I../ -g +TARGET = matrix + +SRC_DIR = ../code +OBJ_DIR = ../.o + +SRCS = $(wildcard $(SRC_DIR)/*.c) +OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS)) + +.PHONY: all clean run + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(TARGET) + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + @mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) -c $< -o $@ + +run: $(TARGET) + ./$(TARGET) < input > output + @cat output + +clean: + rm -rf $(OBJ_DIR) $(TARGET) output diff --git a/1Y-2H/prog/1Practice/var2/run/matrix b/1Y-2H/prog/1Practice/var2/run/matrix new file mode 100755 index 0000000..8e4f8ea Binary files /dev/null and b/1Y-2H/prog/1Practice/var2/run/matrix differ diff --git a/1Y-2H/prog/Lectures/Лекция 14.pdf b/1Y-2H/prog/Lectures/Лекция 14.pdf new file mode 100644 index 0000000..cb7e36c Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 14.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 15.pdf b/1Y-2H/prog/Lectures/Лекция 15.pdf new file mode 100644 index 0000000..b60e349 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 15.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 16.pdf b/1Y-2H/prog/Lectures/Лекция 16.pdf new file mode 100644 index 0000000..f1cf728 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 16.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 17.pdf b/1Y-2H/prog/Lectures/Лекция 17.pdf new file mode 100644 index 0000000..575f7c7 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 17.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 18.pdf b/1Y-2H/prog/Lectures/Лекция 18.pdf new file mode 100644 index 0000000..4eb840a Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 18.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 19.pdf b/1Y-2H/prog/Lectures/Лекция 19.pdf new file mode 100644 index 0000000..e322a9a Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 19.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 20.pdf b/1Y-2H/prog/Lectures/Лекция 20.pdf new file mode 100644 index 0000000..fc25851 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 20.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 21.pdf b/1Y-2H/prog/Lectures/Лекция 21.pdf new file mode 100644 index 0000000..8843820 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 21.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 22.pdf b/1Y-2H/prog/Lectures/Лекция 22.pdf new file mode 100644 index 0000000..d99415e Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 22.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 23.pdf b/1Y-2H/prog/Lectures/Лекция 23.pdf new file mode 100644 index 0000000..fca54a4 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 23.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 24.pdf b/1Y-2H/prog/Lectures/Лекция 24.pdf new file mode 100644 index 0000000..fe936d4 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 24.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 25.pdf b/1Y-2H/prog/Lectures/Лекция 25.pdf new file mode 100644 index 0000000..42f0ac4 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 25.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 26.pdf b/1Y-2H/prog/Lectures/Лекция 26.pdf new file mode 100644 index 0000000..345956d Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 26.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 27.pdf b/1Y-2H/prog/Lectures/Лекция 27.pdf new file mode 100644 index 0000000..ca64127 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 27.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 28.pdf b/1Y-2H/prog/Lectures/Лекция 28.pdf new file mode 100644 index 0000000..527a604 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 28.pdf differ diff --git a/1Y-2H/prog/Lectures/Лекция 29.pdf b/1Y-2H/prog/Lectures/Лекция 29.pdf new file mode 100644 index 0000000..19eafe1 Binary files /dev/null and b/1Y-2H/prog/Lectures/Лекция 29.pdf differ diff --git a/1Y-2H/trpo/done/.clang-format b/1Y-2H/trpo/done/.clang-format new file mode 100644 index 0000000..0bc5a63 --- /dev/null +++ b/1Y-2H/trpo/done/.clang-format @@ -0,0 +1,86 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true +ColumnLimit: 80 +CompactNamespaces: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +IncludeBlocks: Preserve +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... + diff --git a/1Y-2H/trpo/done/.o/chessviz/io.o b/1Y-2H/trpo/done/.o/chessviz/io.o new file mode 100644 index 0000000..b4f7e25 Binary files /dev/null and b/1Y-2H/trpo/done/.o/chessviz/io.o differ diff --git a/1Y-2H/trpo/done/.o/chessviz/logic.o b/1Y-2H/trpo/done/.o/chessviz/logic.o new file mode 100644 index 0000000..48f96d9 Binary files /dev/null and b/1Y-2H/trpo/done/.o/chessviz/logic.o differ diff --git a/1Y-2H/trpo/done/.o/chessviz/main.o b/1Y-2H/trpo/done/.o/chessviz/main.o new file mode 100644 index 0000000..b08dddd Binary files /dev/null and b/1Y-2H/trpo/done/.o/chessviz/main.o differ diff --git a/1Y-2H/trpo/done/README.md b/1Y-2H/trpo/done/README.md new file mode 100644 index 0000000..e0a1951 --- /dev/null +++ b/1Y-2H/trpo/done/README.md @@ -0,0 +1,93 @@ +# lab-rodionov-iv522s18 + + + +## Getting started + +To make it easy for you to get started with GitLab, here's a list of recommended next steps. + +Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! + +## Add your files + +* [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files +* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: + +``` +cd existing_repo +git remote add origin https://git.csc.sibsutis.ru/trpo2026/lab-rodionov-iv522s18.git +git branch -M master +git push -uf origin master +``` + +## Integrate with your tools + +* [Set up project integrations](https://git.csc.sibsutis.ru/trpo2026/lab-rodionov-iv522s18/-/settings/integrations) + +## Collaborate with your team + +* [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) +* [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) +* [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) +* [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) +* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) + +## Test and Deploy + +Use the built-in continuous integration in GitLab. + +* [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) +* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) +* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) +* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) +* [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + +*** + +# Editing this README + +When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. + +## Suggestions for a good README + +Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. + +## Name +Choose a self-explaining name for your project. + +## Description +Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. + +## Badges +On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. + +## Visuals +Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. + +## Installation +Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. + +## Usage +Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. + +## Support +Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. + +## Roadmap +If you have ideas for releases in the future, it is a good idea to list them in the README. + +## Contributing +State if you are open to contributions and what your requirements are for accepting them. + +For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. + +You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. + +## Authors and acknowledgment +Show your appreciation to those who have contributed to the project. + +## License +For open source projects, say how it is licensed. + +## Project status +If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/1Y-2H/trpo/done/chessviz/head.h b/1Y-2H/trpo/done/chessviz/head.h new file mode 100644 index 0000000..7185364 --- /dev/null +++ b/1Y-2H/trpo/done/chessviz/head.h @@ -0,0 +1,32 @@ +#ifndef HEAD +#define HEAD + +// LIBC + #include + #include + #include + +// DEFINE + #define CHARS_IN_INPUT_MAX 40 + +// TYPEDEF + typedef struct{ + unsigned char currCol; + unsigned char currRow; + unsigned char nextCol; + unsigned char nextRow; + unsigned char whosTurn; + }__TURN; + +// FUNC + // === === io.c === === + char input_(char *_input, char *charsInInput); + void print_board(char* _board); + + // === === logic.c === === + char match_turn(char currFigure,char whosTurn); + char match_move(char _board[8][8],__TURN* __turn,char currFigure); + void move(char _board[8][8],__TURN *__turn); + int abs(int n); + +#endif diff --git a/1Y-2H/trpo/done/chessviz/io.c b/1Y-2H/trpo/done/chessviz/io.c new file mode 100644 index 0000000..5ce4d5e --- /dev/null +++ b/1Y-2H/trpo/done/chessviz/io.c @@ -0,0 +1,50 @@ +#include "head.h" + +char input_(char *_input, char *charsInInput){ + + // INPUT + do{ + *charsInInput = 0; + char ch; + while((ch=getchar())>' '&&*charsInInput= '0' && *_input<='9'){ + for(int i = 0;i<*charsInInput;i++) + putchar(_input[i]); + putchar(' '); + continue;} + if((*_input>= 'A' && *_input<='A'+7) || + (*_input>= 'a' && *_input<='a'+7)|| + (*_input=='N'||*_input=='Q'||*_input=='R'||*_input=='K'||*_input=='P')){ + for(int i = 0;i<*charsInInput;i++) + putchar(_input[i]); + putchar('\n'); + break;} + + }while(*_input>4); + + return 0; +} + +void print_board(char* _board){ + for (int i = 0;i<8;i++){ + putchar('8'-i); + putchar(' '); + for(int j = 0;j<8;j++){ + putchar(_board[i*8+j]); + putchar(' '); + } + putchar('\n'); + } + putchar(' ');putchar(' '); + for(int i = 0; i<8;i++){ + putchar('a'+i); + putchar(' '); + } + putchar('\n'); + putchar('\n'); + return; +} diff --git a/1Y-2H/trpo/done/chessviz/logic.c b/1Y-2H/trpo/done/chessviz/logic.c new file mode 100644 index 0000000..28c5f73 --- /dev/null +++ b/1Y-2H/trpo/done/chessviz/logic.c @@ -0,0 +1,225 @@ +#include "head.h" + + +char match_turn(char currFigure,char whosTurn){ + if((currFigure>='a' && currFigure<='z' && whosTurn-1) + // a-z white && turn !white + ||(currFigure>='A' && currFigure<='Z' && whosTurn)){ + // A-Z black && turn white + printf("Err, turn missmatch"); + return 1; + } + return 0; +} + +char match_move(char board[8][8], __TURN* turn, char currFigure) +{ + int rowD = turn->nextRow - turn->currRow; + int colD = turn->nextCol - turn->currCol; + + if (turn->nextRow < 0 || turn->nextRow > 7 || + turn->nextCol < 0 || turn->nextCol > 7) + { + printf("Err, move out of board\n"); + return 1; + } + + switch (currFigure) + { + case 'P': + case 'p': + { + int dir = (currFigure == 'P') ? -1 : 1; + + if (colD == 0) + { + if (board[turn->nextRow][turn->nextCol] != ' ') + return 1; + + if (rowD == dir) + return 0; + + if ((currFigure == 'P' && turn->currRow == 6 && rowD == 2*dir && + board[turn->currRow + dir][turn->currCol] == ' ') || + (currFigure == 'p' && turn->currRow == 1 && rowD == 2*dir && + board[turn->currRow + dir][turn->currCol] == ' ')) + return 0; + } + + if (abs(colD) == 1 && rowD == dir) + { + if (board[turn->nextRow][turn->nextCol] != ' ') + return 0; + } + + printf("Err, pawn move mismatch\n"); + return 1; + } + + case 'R': + case 'r': + { + if (rowD != 0 && colD != 0) + { + printf("Err, rook move mismatch\n"); + return 1; + } + + if (rowD == 0) + { + int step = (colD > 0) ? 1 : -1; + for (int c = turn->currCol + step; + c != turn->nextCol; + c += step) + { + if (board[turn->currRow][c] != ' ') + { + printf("Err, rook blocked\n"); + return 1; + } + } + } + else + { + int step = (rowD > 0) ? 1 : -1; + for (int r = turn->currRow + step; + r != turn->nextRow; + r += step) + { + if (board[r][turn->currCol] != ' ') + { + printf("Err, rook blocked\n"); + return 1; + } + } + } + return 0; + } + + case 'N': + case 'n': + { + if ((abs(rowD) == 2 && abs(colD) == 1) || + (abs(rowD) == 1 && abs(colD) == 2)) + return 0; + printf("Err, knight move mismatch\n"); + return 1; + } + + case 'B': + case 'b': + { + if (abs(rowD) != abs(colD)) + { + printf("Err, bishop move mismatch\n"); + return 1; + } + + int stepR = (rowD > 0) ? 1 : -1; + int stepC = (colD > 0) ? 1 : -1; + int r = turn->currRow + stepR; + int c = turn->currCol + stepC; + + while (r != turn->nextRow && c != turn->nextCol) + { + if (board[r][c] != ' ') + { + printf("Err, bishop blocked\n"); + return 1; + } + r += stepR; + c += stepC; + } + return 0; + } + + case 'Q': + case 'q': + { + if (abs(rowD) == abs(colD)) + { + int stepR = (rowD > 0) ? 1 : -1; + int stepC = (colD > 0) ? 1 : -1; + + int r = turn->currRow + stepR; + int c = turn->currCol + stepC; + + while (r != turn->nextRow && c != turn->nextCol) + { + if (board[r][c] != ' ') + { + printf("Err, queen blocked\n"); + return 1; + } + r += stepR; + c += stepC; + } + return 0; + } + + if (rowD == 0 || colD == 0) + { + if (rowD == 0) + { + int step = (colD > 0) ? 1 : -1; + for (int c = turn->currCol + step; + c != turn->nextCol; + c += step) + { + if (board[turn->currRow][c] != ' ') + { + printf("Err, queen blocked\n"); + return 1; + } + } + } + else + { + int step = (rowD > 0) ? 1 : -1; + for (int r = turn->currRow + step; + r != turn->nextRow; + r += step) + { + if (board[r][turn->currCol] != ' ') + { + printf("Err, queen blocked\n"); + return 1; + } + } + } + return 0; + } + printf("Err, queen move mismatch\n"); + return 1; + } + + case 'K': + case 'k': + { + if (abs(rowD) <= 1 && abs(colD) <= 1) + return 0; + printf("Err, king move mismatch\n"); + return 1; + } + } + + return 1; +} + +void move(char board[8][8], __TURN *turn) +{ + board[turn->nextRow][turn->nextCol] = + board[turn->currRow][turn->currCol]; + + board[turn->currRow][turn->currCol] = ' '; + + turn->whosTurn = turn->whosTurn == 0 ? 1 : 0; +} + + + +int abs(int n){ + n = n<0 ? n*-1:n; + return n; +} + diff --git a/1Y-2H/trpo/done/chessviz/main.c b/1Y-2H/trpo/done/chessviz/main.c new file mode 100644 index 0000000..e9f9a4c --- /dev/null +++ b/1Y-2H/trpo/done/chessviz/main.c @@ -0,0 +1,69 @@ +#include "head.h" + + +int main() +{ + char _board[8][8]; + { //Set Def desk + char _cleanDesk[] = {"rnbqkbnrpppppppp"}; + for(int i = 0;i<8;i++) + for(int j = 0;j<8;j++) + _board[i][j] = ' '; + for (int i = 0; i < 2;i++) + for(int j = 0; j <8;j++) + _board[i][j] = _cleanDesk[i*8+j]; + for (int i = 6; i < 8;i++) + for(int j = 0; j < 8;j++) + _board[i][j] = i==6? (_cleanDesk[8+j])-32 : (_cleanDesk[j])-32; + print_board(*_board); + } + + char charsInInput=1; + char _input[CHARS_IN_INPUT_MAX]; + __TURN __turn; + __turn.whosTurn = 0; // 0 - white 1 - black + while(charsInInput>0){ + if (input_(_input,&charsInInput)) return 0; + unsigned char ptr; + {//Turn info + ptr = (*_input>='A'&&*_input<='Z')?3:2; // Qe2-e4 + __turn.currCol = _input[ptr-2]-'a'; + __turn.currRow = 8-(_input[ptr-1]-'0'); + __turn.nextCol = _input[ptr+1]-'a'; + __turn.nextRow = 8-(_input[ptr+2]-'0'); + } + + {//Rules + char currFigure = _board[__turn.currRow][__turn.currCol]; + { // 'Q'e2-e5 Missmatch + if(ptr==3) + if(*_input!=currFigure&&*_input!=currFigure-32){ + printf("Err, figure missmatch"); + return 1; + } + } + + if(match_turn(currFigure,__turn.whosTurn))return 1; + + { // TAKE MISMATCH + if + ((_board[__turn.nextRow][__turn.nextCol]!=' ' && _input[ptr]!='x' + )||( + _board[__turn.nextRow][__turn.nextCol]==' ' && _input[ptr]=='x')) + { + printf("Err, take missmatch"); + return 1; + } + } + + if(match_move(_board,&__turn,currFigure))return 1; + } + + move(_board,&__turn); + print_board(*_board); + if(_input[charsInInput-1]=='#')break; + } + + + return 0; +} diff --git a/1Y-2H/trpo/done/run/chess_bin b/1Y-2H/trpo/done/run/chess_bin new file mode 100755 index 0000000..832c75c Binary files /dev/null and b/1Y-2H/trpo/done/run/chess_bin differ diff --git a/1Y-2H/trpo/done/run/input b/1Y-2H/trpo/done/run/input new file mode 100644 index 0000000..7e173b5 --- /dev/null +++ b/1Y-2H/trpo/done/run/input @@ -0,0 +1,4 @@ +1. e2-e4 e7-e5 +2. Bf1-c4 Nb8-c6 +3. Qd1-h5 Ng8-f6 +4. Qh5xf7# diff --git a/1Y-2H/trpo/done/run/output b/1Y-2H/trpo/done/run/output new file mode 100644 index 0000000..86abeaf Binary files /dev/null and b/1Y-2H/trpo/done/run/output differ diff --git a/1Y-2H/trpo/lab-rodionov-iv522s18 b/1Y-2H/trpo/lab-rodionov-iv522s18 new file mode 160000 index 0000000..5553e13 --- /dev/null +++ b/1Y-2H/trpo/lab-rodionov-iv522s18 @@ -0,0 +1 @@ +Subproject commit 5553e1330f06b6d49f885dd06be7b4b2dc37f44b diff --git a/tmp.c b/tmp.c new file mode 100644 index 0000000..9a628e1 --- /dev/null +++ b/tmp.c @@ -0,0 +1,15 @@ +#include +//#include +//#include + +int main(){ + //setlocale(LC_ALL, ""); + int a = 69 % 4 + 1; + printf("%d",a); + + //do{ + // wchar_t word[] = L"ТерпимТерпимТеприм\t"; + // for(char i = 0;word[i]!='\0';i++) + // putwchar(word[i]); + //}while(1); +} diff --git a/tmp.out b/tmp.out new file mode 100755 index 0000000..74d62d1 Binary files /dev/null and b/tmp.out differ