Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 14
diff options
context:
space:
mode:
Commit55fc7eb3bba83f4084b2f897c61d0280a5f9c097 (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-10-02 17:44:35 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-10-02 17:44:35 +0300
Files85d32a9a73f85c54162f9233f36a054ebe0de212 /Sem. 14
Introduction_to_programming_FMI-55fc7eb3bba83f4084b2f897c61d0280a5f9c097.tar
Introduction_to_programming_FMI-55fc7eb3bba83f4084b2f897c61d0280a5f9c097.tar.gz
Introduction_to_programming_FMI-55fc7eb3bba83f4084b2f897c61d0280a5f9c097.zip
Parent7f51b56297270d4a1f808bc73d082b71418a2fe0 (diff)
new
8 files changed, 0 insertions, 336 deletions
-rw-r--r--Sem. 14/README.md16
-rw-r--r--Sem. 14/task1.cpp16
-rw-r--r--Sem. 14/task2.cpp25
-rw-r--r--Sem. 14/task3.cpp35
-rw-r--r--Sem. 14/task4.cpp32
-rw-r--r--Sem. 14/task5.cpp110
-rw-r--r--Sem. 14/task6.cpp37
-rw-r--r--Sem. 14/task7.cpp65
diff --git a/Sem. 14/README.md b/Sem. 14/README.md
deleted file mode 100644
index 3288722..0000000
--- a/Sem. 14/README.md
+++ /dev/null
@@ -1,16 +0,0 @@
-**Задача 1:** Да се реализира рекурсивна функция, която пресмята биномен коефициент.
-
-**Задача 2:** Да се напише рекурсивна функция, която пресмята броя единиците и броя на нулите на дадено число.
-
-**Задача 3:** Дадено е поле под формата масив от цели числа. Стойнстта на всяка клетка означава колко голям "скок" можем да направим от тази клетка в друга
-наляво или надясно. Напишете функция, която връща дали може да стигнем от началото до края на масива.
-
-**Задача 4:** Дадено ни е число n и n елемента на масив (от естествени числа). Напишете рекурсивна функция, която провеява дали в масива се съдържат първите n четни числа (точно веднъж).
-
-**Задача 5:** Въвеждат се две изречения (с макс дължина 1024). Да се напише функция, която проверява дали изреченията са от еднакви думи (между думите може да има произволен брой интервали).
-
-**Задача 6:** Даден е правоъгълник с размери NxM. Да се напише функция, която връща дали правоъгълникът може да бъде покрит с плочки 1x2 и 3x1.
-
-**Задача 7:** Дадено е изречение. Да се реализира функция, която обръща реда на думите в изречението.
-
- Пример: **Вход**: "How are you friends. I am fine!", **Изход**: "fine! am I friends. you are How"
diff --git a/Sem. 14/task1.cpp b/Sem. 14/task1.cpp
deleted file mode 100644
index 01d4eb9..0000000
--- a/Sem. 14/task1.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-using namespace std;
-
-unsigned binom(unsigned n, unsigned k)
-{
- if (n < k)
- return 0;
- if (n == k || k == 0)
- return 1;
- return binom(n - 1, k) + binom(n - 1, k - 1);
-}
-
-int main()
-{
-
-} \ No newline at end of file
diff --git a/Sem. 14/task2.cpp b/Sem. 14/task2.cpp
deleted file mode 100644
index f22e9ae..0000000
--- a/Sem. 14/task2.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <iostream>
-using namespace std;
-
-void countBinaryElements(unsigned n, unsigned& zeros, unsigned& ones)
-{
- if (n == 0)
- return;
-
- int lastBit = n % 2;
- if (lastBit == 1)
- ones++;
- else if (lastBit == 0)
- zeros++;
- countBinaryElements(n >> 1, zeros, ones);
-
-}
-int main()
-{
- int n;
- cin >> n;
-
- unsigned ones = 0, zeros = 0;
- countBinaryElements(n, ones, zeros);
- cout << ones << " " << zeros;
-} \ No newline at end of file
diff --git a/Sem. 14/task3.cpp b/Sem. 14/task3.cpp
deleted file mode 100644
index 5df4d01..0000000
--- a/Sem. 14/task3.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <iostream>
-using namespace std;
-
-bool checkIfPathExists(const int* field, bool* visited, int len, int pos)
-{
- if (pos < 0 || pos >= len || visited[pos]) //out of bounds
- return false;
- if (pos == len - 1)
- return true;
-
- visited[pos] = true;
-
- int value = field[pos];
-
- return checkIfPathExists(field, visited, len, pos - value) || checkIfPathExists(field, visited, len, pos + value);
-
-}
-
-int main()
-{
- int n;
- cin >> n; //ãîëåìèíàòà íà ìàñèâà.
- int* field = new int[n];
- bool* visited = new bool[n];
-
- for (int i = 0; i < n; i++)
- {
- cin >> field[i];
- visited[i] = false;
- }
-
- cout << checkIfPathExists(field, visited, n, 0);
-
- delete[] field, visited;
-}
diff --git a/Sem. 14/task4.cpp b/Sem. 14/task4.cpp
deleted file mode 100644
index b48b521..0000000
--- a/Sem. 14/task4.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <iostream>
-using namespace std;
-
-bool checkIfContainsFirstNEvenNumbers(const unsigned* arr, bool* visited, int len, int n)
-{
- if (len == 0)
- return true; //all values in visited should be true
-
- int currentNumber = arr[0];
- if (currentNumber % 2 != 0 || currentNumber > 2 * n - 2 || visited[currentNumber / 2])
- return false;
-
- visited[currentNumber / 2] = true;
-
- return checkIfContainsFirstNEvenNumbers(arr + 1, visited, len - 1, n);
-
-}
-int main()
-{
- int n;
- cin >> n;
- unsigned* arr = new unsigned[n];
- bool* visited = new bool[n];
- for (int i = 0; i < n; i++)
- {
- cin >> arr[i];
- visited[i] = false;
- }
-
- cout << checkIfContainsFirstNEvenNumbers(arr, visited, n, n);
- delete[] arr, visited;
-} \ No newline at end of file
diff --git a/Sem. 14/task5.cpp b/Sem. 14/task5.cpp
deleted file mode 100644
index 4301cee..0000000
--- a/Sem. 14/task5.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-#include <iostream>
-using namespace std;
-
-
-const int MAX_LEN = 1024;
-
-//returns -1 if searched is not found in str. returns the index otherwise.
-int contains(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;
-}
-bool containsOnlyWhiteSpaces(const char* str)
-{
- while (*str != '\0')
- {
- if (*str != ' ')
- return false;
- str++;
- }
- return true;
-}
-void makeSpaces(char* str, int startIndex, int spacesCount)
-{
- for (int i = startIndex; i < startIndex + spacesCount; i++)
- str[i] = ' ';
-}
-bool hasSameWords(const char* sentence1, const char* sentence2)
-{
- int len1 = strlen(sentence1);
- int len2 = strlen(sentence2);
-
- char* s1 = new char[len1 + 1];
- char* s2 = new char[len2 + 1];
-
- char* s1Original = s1;// we change s1. So we could delete the whole array
-
- strcpy(s1, sentence1);
- strcpy(s2, sentence2);
-
-
- for (int i = 0; i <= len1; i++)
- {
- if (s1[i] != ' ' &&s1[i] != '\0' )
- continue;
- //we are here if we found a space (or a \0 which means it's the last word).
-
-
- //if the space is at the begining, there is not a word before it. So we just remove it.
- if (i == 0)
- {
- s1 += 1;
- len1--;
- i = -1; // so it could become 0 for the next iteration
- continue;
- }
-
- char* currentWord = new char[i + 1];
-
- s1[i] = '\0';
- strcpy(currentWord, s1);
-
- if (i != len1) //if it's not the last word (because after the last word there is an '\0').
- s1[i] = ' ';
-
- int res = contains(s2, currentWord);
- if (res == -1)
- return false;
-
- //we make the matched word as whitespaces.
- makeSpaces(s1, 0, i);
- makeSpaces(s2, res, i);
-
- //we move the pointer to continue with the sentense.
- s1 += i;
- len1 -= i;
-
- i = -1; // so it could become 0 for the next iteration
- delete[] currentWord;
- }
-
- bool res = containsOnlyWhiteSpaces(s1Original) && containsOnlyWhiteSpaces(s2);
- delete[] s1Original, s2;
- return res;
-}
-int main()
-{
- char sentence1[MAX_LEN];
- char sentence2[MAX_LEN];
-
- //cin.getline(sentence1, MAX_LEN);
- //cin.getline(sentence2, MAX_LEN);
-
- cout << hasSameWords("hello friends bye enemy", "bye friends hello enemy");
-}
diff --git a/Sem. 14/task6.cpp b/Sem. 14/task6.cpp
deleted file mode 100644
index 9d0de4b..0000000
--- a/Sem. 14/task6.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <iostream>
-using namespace std;
-
-bool canBeCovered(int n, int m)
-{
- if ((n == 0 && m >= 0) || (n>=0 && m==0)) //empty rectangle can be covered
- return true;
-
- if (n < 0 || m < 0) //out of range
- return false;
-
- if ((n == 1 && m == 2) || (n == 3 && m == 1)) //exactly one 1x2 or 3x1
- return true;
-
- if ((n == 1 && m == 1) || (n == 2 && m == 1)) // to swall for our plates
- return false;
-
-
-
- //if the plate 1x2 stands in the top left corner
- bool case1 = (m >=2 && canBeCovered(n - 1, 2) && canBeCovered(n, m - 2)) //try cut vertically
- || (n>=1 && canBeCovered(n-1, m) && canBeCovered(1, m-2)); //try cut horizontaly
-
- if (case1)
- return true;
-
- //if the plate 3x1 stands in the top left corner
- bool case2 = (m >= 1 && canBeCovered(n - 3, 1) && canBeCovered(n, m - 1)) //try cut vertically
- || (n>=3 && canBeCovered(3, m - 1) && canBeCovered(n - 3, m)); //try cut horizontaly
-
- return case2;
-}
-int main()
-{
- int n, m;
- cout << canBeCovered(4, 3);
-}
diff --git a/Sem. 14/task7.cpp b/Sem. 14/task7.cpp
deleted file mode 100644
index 726a0f2..0000000
--- a/Sem. 14/task7.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include <iostream>
-#include <cstring>
-using namespace std;
-
-const int MAXLEN = 1024;
-
-//creates a matrix of the words in the sentence.
-int fillWords(const char* str, char words[MAXLEN][MAXLEN])
-{
- int len = strlen(str);
-
- int currentWordCursorInMatrix = 0;
- int count = 0 ; //also the index of the row in the matrix.
-
- for(int i = 0; i < len; i++)
- {
- if(str[i] == ' ') // the current word ends here.
- {
- if(currentWordCursorInMatrix != 0) // check if we have writen at least one symbol in the current word.
- {
- words[count][currentWordCursorInMatrix] = '\0';
- count++;
- currentWordCursorInMatrix = 0;
- }
- }
- else
- {
- words[count][currentWordCursorInMatrix] = str[i]; // we write the symbol in the current word.
- currentWordCursorInMatrix++;
- }
- }
- if(str[len-1] != ' ')
- count++; //the last word;
- return count;
-
-}
-
-void createReversedSentence(char words[MAXLEN][MAXLEN], int wordsCount, char* newSentence)
-{
-
- for (int j = wordsCount - 1; j >= 0 ; j--)
- {
- strcat(newSentence, words[j]);
- if(j != 0)
- strcat(newSentence, " "); //the space between the words
- }
-}
-int main()
-{
- const char* str = "How are you friends. I am fine!";
-
- char words[MAXLEN][MAXLEN];
-
- int wordsCount = fillWords(str, words);
-
- char* newSentense = new char[strlen(str)];
-
- createReversedSentence(words, wordsCount, newSentense);
-
- cout << newSentense << endl;
-
- delete[] newSentense;
-
- return 0;
-}