diff options
new
6 files changed, 0 insertions, 277 deletions
| -rw-r--r-- | Sem. 12/README.md | 29 | ||||
| -rw-r--r-- | Sem. 12/dynamic_memory.cpp | 27 | ||||
| -rw-r--r-- | Sem. 12/references.cpp | 22 | ||||
| -rw-r--r-- | Sem. 12/task1.cpp | 54 | ||||
| -rw-r--r-- | Sem. 12/task3.cpp | 89 | ||||
| -rw-r--r-- | Sem. 12/tesk2.cpp | 56 |
diff --git a/Sem. 12/README.md b/Sem. 12/README.md deleted file mode 100644 index 1246379..0000000 --- a/Sem. 12/README.md +++ /dev/null @@ -1,29 +0,0 @@ -**Задача 1:** Напишете функция, която приема стринг и връща нов стринг, в който са премахнати всички цифри от първия стринг. -Новият стринг да е с точна дължина. - -**Пример:** - -**Вход:** "ivan454sdd" - -**Изход:** "ivanssd" - -**Задача 2:** Да се реализира функция, която приема масив, в който всеки елемент се среща 2 пъти, с изключение на един елемент, който се среща точно веднъж. -Функцията да връща кой е този елемент. - -**Пример:** - -**Вход:** [3, 5, 6, 5, 3, 7, 8, 8, 7] - -**Изход:** 6 - -**Задача 3:** Напишете функция, която примема стринг A, стринг X и приема и стринг Y и замества всяко срещане на X в А с Y. -Новият стринг да е с точна дължина. - -**Пример:** -A = "hello friends! You are my best friend. I have no other friends!" - -X = "friend" - -Y = "enemy" - -**Резултат:** "hello enemys! You are my best enemy. I have no other enemys!" diff --git a/Sem. 12/dynamic_memory.cpp b/Sem. 12/dynamic_memory.cpp deleted file mode 100644 index 6d45a1d..0000000 --- a/Sem. 12/dynamic_memory.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include <iostream> -using namespace std; - -int main() -{ - int arr[3]; //големината на тези масиви трябва да е ясна ПРЕДИ да се компилира програмата - //паметта за стека трябва да се задели преди да тръгне програмата - if (true) - { - int num = 10; - num++; - } - //num++; //стекът сам си "чисти" паметта. Променливата num не съществува. - - int n; - cin >> n; - int* arr = new int[n];// Тук n е променлива - стойността и НЕ е ясна преди да тръгне програмата! - - /*if (true) - { - arr = new int[2*n] // Отечка на памет (memory leak).Не е изтрита паметта, към която сочи arr. - }*/ - delete[] arr; - //За всяко едно new трябва да имаме едно delete. - //Уговаряме се, че ЩЕ БЪДЕ В СЪЩАТА ФУНЦКИЯ. - //Т.е няма да заделяме памет в една функция и да я освобождаваме в друга! -} diff --git a/Sem. 12/references.cpp b/Sem. 12/references.cpp deleted file mode 100644 index 5922d33..0000000 --- a/Sem. 12/references.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include <iostream> -using namespace std; - -void f(int a) -{ - a += 5; - -} -void f2(int& a) -{ - a += 5; -} - -int main() -{ - int x = 10; - f(x); - cout << x << endl; //10 - - f2(x); - cout << x << endl; //15 -} diff --git a/Sem. 12/task1.cpp b/Sem. 12/task1.cpp deleted file mode 100644 index 1698c33..0000000 --- a/Sem. 12/task1.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include <iostream> -using namespace std; - -bool isDigit(char ch) -{ - return ch >= '0' && ch <= '9'; -} -int countDigits(const char* str) -{ - //int len = strlen(str); - //int count = 0; - //for (int i = 0; i < len; i++) - //{ - // if (isDigit(str[i])) - // count++; - //} - - int count = 0; - while (*str != '\0') - { - if (isDigit(*str)) - count++; - str++; - } - return count; -} - -void removeDigits(const char* str, char* resultStr) -{ - while (*str != '\0') - { - if (!isDigit(*str)) - { - *resultStr = *str; - resultStr++; - } - str++; - } - *resultStr = '\0'; -} -int main() -{ - const char* str = "hello friends 123 , how are you? 343. Fine!"; - - int len = strlen(str) - countDigits(str); - - char* resultStr = new char[len + 1]; - - removeDigits(str, resultStr); - - cout << resultStr << endl; - - delete[] resultStr; -}
\ No newline at end of file diff --git a/Sem. 12/task3.cpp b/Sem. 12/task3.cpp deleted file mode 100644 index ba0ba1b..0000000 --- a/Sem. 12/task3.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include <iostream> -using namespace std; - -int search(const char* string, const char* searched); - -void replace(const char* string, const char* x, const char* y, char* result) -{ - int yLen = strlen(y); - int xLen = strlen(x); - while (true) - { - int indX = search(string, x); //14 - if (indX == -1) - break; - - - for (int i = 0; i < indX; i++) - result[i] = string[i]; - result += indX; - string += indX + xLen; - - for (int i = 0; i < yLen; i++) - result[i] = y[i]; - result += yLen; - } - - //the rest symbols - while (*string != '\0') - { - *result = *string; - result++; - string++; - } - *result = '\0'; - -} - -//return the first index of searched in str. -int search(const char* str, const char* searched) -{ - int len1 = strlen(str); - int len2 = strlen(searched); - for (int i = 0; i < len1 - len2+1; i++) - { - bool found = true; - for (int j = 0; j < len2; j++) - { - if (searched[j] != str[i + j]) - { - found = false; - break; - } - } - if (found) - return i; - } - return -1; -} -int countOccurrences(const char* str, const char* searched) -{ - int count = 0; - - int searchLen = strlen(searched); - int ind = search(str, searched); - while (ind != -1) - { - count++; - str += (ind + searchLen); - ind = search(str, searched); - } - return count; -} -int main() -{ - const char* str = "hello friends! You are my best friends. I have no other friends"; - const char* x = "friend"; - const char* y = "enemy"; - - int len = strlen(str); - int xOccurrences = countOccurrences(str, x); - - char* result = new char[len - xOccurrences*strlen(x) + xOccurrences*strlen(y) + 1]; - - replace(str, x, y, result); - - cout << result << endl; - - delete[] result; -}
\ No newline at end of file diff --git a/Sem. 12/tesk2.cpp b/Sem. 12/tesk2.cpp deleted file mode 100644 index e41c069..0000000 --- a/Sem. 12/tesk2.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include <iostream> -using namespace std; - -bool isSymbol(char ch) -{ - return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'); -} -bool isVowel(char ch) -{ - switch (ch) - { - case 'A': - case 'O': - case 'I': - case 'U': - case 'E': - case 'a': - case 'o': - case 'i': - case 'u': - case 'e':return true; - } - return false; -} -void countVowelAndCons(const char* str, int& vowelCount, int& consCount) -{ - while (*str != '\0') - { - if (isSymbol(*str)) - { - if (isVowel(*str)) - vowelCount++; - else - consCount++; - } - str++; - } -} - -bool isBalanced(const char* str) -{ - int vowelCount = 0, consCount = 0; - - countVowelAndCons(str, vowelCount, consCount); - - return vowelCount == consCount; -} - -int main() -{ - const char* str = "TestMeau"; - - cout << isBalanced(str) << endl; - - -} |
