From 7881119e0914b9207568918fcf868eea84ef3d78 Mon Sep 17 00:00:00 2001 From: Angeld55 Date: Sat, 28 Nov 2020 01:45:44 +0200 Subject: sem 8 --- Sem. 01/Variables.cpp | 117 +++++++++++++++++++ Sem. 02/Even_Odd.cpp | 17 +++ Sem. 02/Grades.cpp | 63 ++++++++++ Sem. 02/Operators_priority.png | Bin 0 -> 22886 bytes Sem. 02/dayOfWeek.cpp | 22 ++++ Sem. 02/isPrime_between[1,9].cpp | 26 +++++ Sem. 03/Contains5.cpp | 32 +++++ Sem. 03/DevidersCount_PrimalityCheck.cpp | 29 +++++ Sem. 03/GCD_solution1.cpp | 32 +++++ Sem. 03/GCD_solution2.cpp | 35 ++++++ Sem. 03/GCD_solution3_Eucid.cpp | 25 ++++ Sem. 03/PrintEvenNumbers.cpp | 27 +++++ Sem. 03/SumOfDigits.cpp | 22 ++++ .../Tasks and Solutions/01. Between100and200.cpp | 15 +++ Sem. 03/Tasks and Solutions/02. Speed check.cpp | 19 +++ Sem. 03/Tasks and Solutions/03. Figures.cpp | 28 +++++ Sem. 03/Tasks and Solutions/04. Time + 15.cpp | 21 ++++ Sem. 03/Tasks and Solutions/05. Chainsaw.cpp | 16 +++ Sem. 03/Tasks and Solutions/06. DivBy3.cpp | 11 ++ Sem. 03/Tasks and Solutions/07. ContainsDigit.cpp | 20 ++++ .../Tasks and Solutions/08. DuplicateDigits.cpp | 93 +++++++++++++++ Sem. 03/Tasks and Solutions/09. SumFromKtoN.cpp | 18 +++ Sem. 03/Tasks and Solutions/10. Pyramid.cpp | 14 +++ Sem. 03/Tasks and Solutions/11. Clock.cpp | 18 +++ Sem. 03/Tasks and Solutions/12. ClockWithStart.cpp | 31 +++++ .../13. ClockWithStartAndEnd.cpp | 41 +++++++ Sem. 03/Tasks and Solutions/14. Frame.cpp | 30 +++++ Sem. 03/Tasks and Solutions/tasks.pdf | Bin 0 -> 449792 bytes Sem. 04/README.md | 129 +++++++++++++++++++++ Sem. 04/Task1.cpp | 14 +++ Sem. 04/Task2.cpp | 17 +++ Sem. 04/Task3.cpp | 10 ++ Sem. 04/Task4.cpp | 10 ++ Sem. 04/bitwise_examples.cpp | 20 ++++ Sem. 05/README.md | 18 +++ Sem. 05/Task 1.cpp | 58 +++++++++ Sem. 05/Task 2.cpp | 39 +++++++ Sem. 05/Task 3.cpp | 27 +++++ Sem. 05/Task 4.cpp | 23 ++++ Sem. 05/Task 5.cpp | 33 ++++++ Sem. 05/Task 6.cpp | 19 +++ Sem. 06/README.md | 35 ++++++ Sem. 06/Task_1(with functions).cpp | 26 +++++ Sem. 06/Task_1(without functions).cpp | 40 +++++++ Sem. 06/Tasks_2,3,4,5,6,7,8,9,10.cpp | 108 +++++++++++++++++ Sem. 07/BullsAndColls.cpp | 100 ++++++++++++++++ Sem. 07/README.md | 9 ++ Sem. 08/README.md | 35 ++++++ Sem. 08/task1.cpp | 17 +++ Sem. 08/task2.cpp | 42 +++++++ Sem. 08/task3.cpp | 49 ++++++++ Sem. 1/Variables.cpp | 117 ------------------- Sem. 2/Even_Odd.cpp | 17 --- Sem. 2/Grades.cpp | 63 ---------- Sem. 2/Operators_priority.png | Bin 22886 -> 0 bytes Sem. 2/dayOfWeek.cpp | 22 ---- Sem. 2/isPrime_between[1,9].cpp | 26 ----- Sem. 3/Contains5.cpp | 32 ----- Sem. 3/DevidersCount_PrimalityCheck.cpp | 29 ----- Sem. 3/GCD_solution1.cpp | 32 ----- Sem. 3/GCD_solution2.cpp | 35 ------ Sem. 3/GCD_solution3_Eucid.cpp | 25 ---- Sem. 3/PrintEvenNumbers.cpp | 27 ----- Sem. 3/SumOfDigits.cpp | 22 ---- .../Tasks and Solutions/01. Between100and200.cpp | 15 --- Sem. 3/Tasks and Solutions/02. Speed check.cpp | 19 --- Sem. 3/Tasks and Solutions/03. Figures.cpp | 28 ----- Sem. 3/Tasks and Solutions/04. Time + 15.cpp | 21 ---- Sem. 3/Tasks and Solutions/05. Chainsaw.cpp | 16 --- Sem. 3/Tasks and Solutions/06. DivBy3.cpp | 11 -- Sem. 3/Tasks and Solutions/07. ContainsDigit.cpp | 20 ---- Sem. 3/Tasks and Solutions/08. DuplicateDigits.cpp | 93 --------------- Sem. 3/Tasks and Solutions/09. SumFromKtoN.cpp | 18 --- Sem. 3/Tasks and Solutions/10. Pyramid.cpp | 14 --- Sem. 3/Tasks and Solutions/11. Clock.cpp | 18 --- Sem. 3/Tasks and Solutions/12. ClockWithStart.cpp | 31 ----- .../13. ClockWithStartAndEnd.cpp | 41 ------- Sem. 3/Tasks and Solutions/14. Frame.cpp | 30 ----- Sem. 3/Tasks and Solutions/tasks.pdf | Bin 449792 -> 0 bytes Sem. 4/README.md | 129 --------------------- Sem. 4/Task1.cpp | 14 --- Sem. 4/Task2.cpp | 17 --- Sem. 4/Task3.cpp | 10 -- Sem. 4/Task4.cpp | 10 -- Sem. 4/bitwise_examples.cpp | 20 ---- Sem. 5/README.md | 18 --- Sem. 5/Task 1.cpp | 58 --------- Sem. 5/Task 2.cpp | 39 ------- Sem. 5/Task 3.cpp | 27 ----- Sem. 5/Task 4.cpp | 23 ---- Sem. 5/Task 5.cpp | 33 ------ Sem. 5/Task 6.cpp | 19 --- Sem. 6/README.md | 35 ------ Sem. 6/Task_1(with functions).cpp | 26 ----- Sem. 6/Task_1(without functions).cpp | 40 ------- Sem. 6/Tasks_2,3,4,5,6,7,8,9,10.cpp | 108 ----------------- Sem. 7/BullsAndColls.cpp | 100 ---------------- Sem. 7/README.md | 9 -- 98 files changed, 1700 insertions(+), 1557 deletions(-) create mode 100644 Sem. 01/Variables.cpp create mode 100644 Sem. 02/Even_Odd.cpp create mode 100644 Sem. 02/Grades.cpp create mode 100644 Sem. 02/Operators_priority.png create mode 100644 Sem. 02/dayOfWeek.cpp create mode 100644 Sem. 02/isPrime_between[1,9].cpp create mode 100644 Sem. 03/Contains5.cpp create mode 100644 Sem. 03/DevidersCount_PrimalityCheck.cpp create mode 100644 Sem. 03/GCD_solution1.cpp create mode 100644 Sem. 03/GCD_solution2.cpp create mode 100644 Sem. 03/GCD_solution3_Eucid.cpp create mode 100644 Sem. 03/PrintEvenNumbers.cpp create mode 100644 Sem. 03/SumOfDigits.cpp create mode 100644 Sem. 03/Tasks and Solutions/01. Between100and200.cpp create mode 100644 Sem. 03/Tasks and Solutions/02. Speed check.cpp create mode 100644 Sem. 03/Tasks and Solutions/03. Figures.cpp create mode 100644 Sem. 03/Tasks and Solutions/04. Time + 15.cpp create mode 100644 Sem. 03/Tasks and Solutions/05. Chainsaw.cpp create mode 100644 Sem. 03/Tasks and Solutions/06. DivBy3.cpp create mode 100644 Sem. 03/Tasks and Solutions/07. ContainsDigit.cpp create mode 100644 Sem. 03/Tasks and Solutions/08. DuplicateDigits.cpp create mode 100644 Sem. 03/Tasks and Solutions/09. SumFromKtoN.cpp create mode 100644 Sem. 03/Tasks and Solutions/10. Pyramid.cpp create mode 100644 Sem. 03/Tasks and Solutions/11. Clock.cpp create mode 100644 Sem. 03/Tasks and Solutions/12. ClockWithStart.cpp create mode 100644 Sem. 03/Tasks and Solutions/13. ClockWithStartAndEnd.cpp create mode 100644 Sem. 03/Tasks and Solutions/14. Frame.cpp create mode 100644 Sem. 03/Tasks and Solutions/tasks.pdf create mode 100644 Sem. 04/README.md create mode 100644 Sem. 04/Task1.cpp create mode 100644 Sem. 04/Task2.cpp create mode 100644 Sem. 04/Task3.cpp create mode 100644 Sem. 04/Task4.cpp create mode 100644 Sem. 04/bitwise_examples.cpp create mode 100644 Sem. 05/README.md create mode 100644 Sem. 05/Task 1.cpp create mode 100644 Sem. 05/Task 2.cpp create mode 100644 Sem. 05/Task 3.cpp create mode 100644 Sem. 05/Task 4.cpp create mode 100644 Sem. 05/Task 5.cpp create mode 100644 Sem. 05/Task 6.cpp create mode 100644 Sem. 06/README.md create mode 100644 Sem. 06/Task_1(with functions).cpp create mode 100644 Sem. 06/Task_1(without functions).cpp create mode 100644 Sem. 06/Tasks_2,3,4,5,6,7,8,9,10.cpp create mode 100644 Sem. 07/BullsAndColls.cpp create mode 100644 Sem. 07/README.md create mode 100644 Sem. 08/README.md create mode 100644 Sem. 08/task1.cpp create mode 100644 Sem. 08/task2.cpp create mode 100644 Sem. 08/task3.cpp delete mode 100644 Sem. 1/Variables.cpp delete mode 100644 Sem. 2/Even_Odd.cpp delete mode 100644 Sem. 2/Grades.cpp delete mode 100644 Sem. 2/Operators_priority.png delete mode 100644 Sem. 2/dayOfWeek.cpp delete mode 100644 Sem. 2/isPrime_between[1,9].cpp delete mode 100644 Sem. 3/Contains5.cpp delete mode 100644 Sem. 3/DevidersCount_PrimalityCheck.cpp delete mode 100644 Sem. 3/GCD_solution1.cpp delete mode 100644 Sem. 3/GCD_solution2.cpp delete mode 100644 Sem. 3/GCD_solution3_Eucid.cpp delete mode 100644 Sem. 3/PrintEvenNumbers.cpp delete mode 100644 Sem. 3/SumOfDigits.cpp delete mode 100644 Sem. 3/Tasks and Solutions/01. Between100and200.cpp delete mode 100644 Sem. 3/Tasks and Solutions/02. Speed check.cpp delete mode 100644 Sem. 3/Tasks and Solutions/03. Figures.cpp delete mode 100644 Sem. 3/Tasks and Solutions/04. Time + 15.cpp delete mode 100644 Sem. 3/Tasks and Solutions/05. Chainsaw.cpp delete mode 100644 Sem. 3/Tasks and Solutions/06. DivBy3.cpp delete mode 100644 Sem. 3/Tasks and Solutions/07. ContainsDigit.cpp delete mode 100644 Sem. 3/Tasks and Solutions/08. DuplicateDigits.cpp delete mode 100644 Sem. 3/Tasks and Solutions/09. SumFromKtoN.cpp delete mode 100644 Sem. 3/Tasks and Solutions/10. Pyramid.cpp delete mode 100644 Sem. 3/Tasks and Solutions/11. Clock.cpp delete mode 100644 Sem. 3/Tasks and Solutions/12. ClockWithStart.cpp delete mode 100644 Sem. 3/Tasks and Solutions/13. ClockWithStartAndEnd.cpp delete mode 100644 Sem. 3/Tasks and Solutions/14. Frame.cpp delete mode 100644 Sem. 3/Tasks and Solutions/tasks.pdf delete mode 100644 Sem. 4/README.md delete mode 100644 Sem. 4/Task1.cpp delete mode 100644 Sem. 4/Task2.cpp delete mode 100644 Sem. 4/Task3.cpp delete mode 100644 Sem. 4/Task4.cpp delete mode 100644 Sem. 4/bitwise_examples.cpp delete mode 100644 Sem. 5/README.md delete mode 100644 Sem. 5/Task 1.cpp delete mode 100644 Sem. 5/Task 2.cpp delete mode 100644 Sem. 5/Task 3.cpp delete mode 100644 Sem. 5/Task 4.cpp delete mode 100644 Sem. 5/Task 5.cpp delete mode 100644 Sem. 5/Task 6.cpp delete mode 100644 Sem. 6/README.md delete mode 100644 Sem. 6/Task_1(with functions).cpp delete mode 100644 Sem. 6/Task_1(without functions).cpp delete mode 100644 Sem. 6/Tasks_2,3,4,5,6,7,8,9,10.cpp delete mode 100644 Sem. 7/BullsAndColls.cpp delete mode 100644 Sem. 7/README.md diff --git a/Sem. 01/Variables.cpp b/Sem. 01/Variables.cpp new file mode 100644 index 0000000..f793a65 --- /dev/null +++ b/Sem. 01/Variables.cpp @@ -0,0 +1,117 @@ +#include +using namespace std; + + +int main() +{ + //The reason why operator = returns a value! + int a, b, c, d, e, f; + a = b = c = d = e = f = 5; + + //Types + int t1 = 4; + double t2 = 4.5; + char t3 = 'v'; + bool t4 = true; + + + //Operators + + //Arithmetic operators + int num1 = 5; + int num2 = 2; + + int result = a + b; //7 + result = a - b; //3 + result = a * b; //10 + result = a / b; // 2 (not 2.5) (both are ints) + result = a%b; //1 5:2 = 2 (rem :1) + + double num2Copy = 2; + double resultCopy = num1 / num2Copy; //2.5 (one of the variables is a double) + + int A = 5; + int B = 2; + + cout << (A++ - B) << endl;// 3 (but A becomes 6) + A = 5;//let's make it 5 again + cout << (++A - B) << endl;//4 (A becomes 6) + + // Comparison operators + + int N1 = 5; + int N2 = 6; + + cout << (N1 > N2)< N2; + cout << cond; + + + //Other comparison operators : ==, !=, >, <, >=,<= + + + + //Logical operators + + bool var1 = false; + bool var2 = true; + + bool t1 = var1 && var2; //false; + bool t2 = var1 || var2; //true + bool t3 = var1 ^ var2; //true + + + //Type casting + + int a1 = 97; + double b1 = a1; + char c1 = a1; + bool d1 = a1; + + cout << a1 << endl; //97 + cout << b1 << endl; //97.0 + cout << c1 << endl; //a + cout << d1 << endl; //1 + + + double b2 = 65.5; + int a2 = b2; + char c2 = b2; + bool d2 = b2; + + cout << b2 << endl; //65.5 + cout << a2 << endl; //65 + cout << c2 << endl; //A + cout << d2 << endl; //1 + + + char c3 = 'a'; + double b3 = c3; + int a3 = c3; + bool d3 = c3; + + cout << c3 << endl; //a + cout << b3 << endl; //97 + cout << a3 << endl; //97 + cout << d3 << endl; //1 + + bool d4 = true; + int a4 = d4; + double b4 = d4; + char c4 = d4; + + cout << c4 << endl; // ?? + cout << b4 << endl; // 1 + cout << a4 << endl; // 1 + cout << d4 << endl; // 1 + + int grade = 5; + + bool isValid = grade >= 2 && grade <= 6; + bool isValid2 = grade == 2 || grade == 3 || grade == 4 || grade == 5||grade == 6; + + bool isNotValid = !isValid; + bool isNotValid2 = grade < 2 || grade>6; + +} diff --git a/Sem. 02/Even_Odd.cpp b/Sem. 02/Even_Odd.cpp new file mode 100644 index 0000000..89c2ecd --- /dev/null +++ b/Sem. 02/Even_Odd.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() +{ + int number; + cin >> number; + + if (number % 2 == 0) + { + std::cout << "Even" << endl; + } + else + { + std::cout << "Odd" << endl; + } +} \ No newline at end of file diff --git a/Sem. 02/Grades.cpp b/Sem. 02/Grades.cpp new file mode 100644 index 0000000..18e1538 --- /dev/null +++ b/Sem. 02/Grades.cpp @@ -0,0 +1,63 @@ + +#include +using namespace std; + +int main() +{ + int grade; + cin >> grade; + + //Bad + if (grade == 2) + { + cout << "Poor" << endl; + } + if (grade == 3) + { + cout << "Average" << endl; + } + if (grade == 4) + { + cout << "Good" << endl; + } + if (grade == 5) + { + cout << "Very good" << endl; + } + if (grade == 6) + { + cout << "Excellent" << endl; + } + if (grade < 2 || grade > 6) + { + cout << "Invalid" << endl; + } + //This works! But when we find a match, we continue checking, even though we don't need to. + + //Better + if (grade == 2) + { + cout << "Poor" << endl; + } + else if (grade == 3) + { + cout << "Average" << endl; + } + else if (grade == 4) + { + cout << "Good" << endl; + } + else if (grade == 5) + { + cout << "Very good" << endl; + } + else if (grade == 6) + { + cout << "Excellent" << endl; + } + else + { + cout << "Invalid" << endl; + } + +} \ No newline at end of file diff --git a/Sem. 02/Operators_priority.png b/Sem. 02/Operators_priority.png new file mode 100644 index 0000000..07d2565 Binary files /dev/null and b/Sem. 02/Operators_priority.png differ diff --git a/Sem. 02/dayOfWeek.cpp b/Sem. 02/dayOfWeek.cpp new file mode 100644 index 0000000..b9640c3 --- /dev/null +++ b/Sem. 02/dayOfWeek.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int main() +{ + int num; + cin >> num; + + switch (num) + { + case 1:cout << "Monday" << endl; break; + case 2:cout << "Tuesday" << endl; break; + case 3:cout << "Wednesday" << endl; break; + case 4:cout << "Thursday" << endl; break; + case 5:cout << "Friday" << endl; break; + case 6:cout << "Saturday" << endl; break; + case 7:cout << "Sunday" << endl; break; + + default: cout << "The number is not a valid day of the week" << endl; + } + +} \ No newline at end of file diff --git a/Sem. 02/isPrime_between[1,9].cpp b/Sem. 02/isPrime_between[1,9].cpp new file mode 100644 index 0000000..08d8445 --- /dev/null +++ b/Sem. 02/isPrime_between[1,9].cpp @@ -0,0 +1,26 @@ + +#include +using namespace std; + +int main() +{ + int num; + cin >> num; + + switch (num) + { + case 2: + case 3: + case 5: + case 7:cout << "Prime" << endl; break; + + case 1: + case 4: + case 6: + case 8: + case 9:cout << "Not a prime" << endl; break; + + default: cout << "The number is not between 1 and 10" << endl; break; + } + +} \ No newline at end of file diff --git a/Sem. 03/Contains5.cpp b/Sem. 03/Contains5.cpp new file mode 100644 index 0000000..78d13f0 --- /dev/null +++ b/Sem. 03/Contains5.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + + bool foundFive = false; + while (n != 0) + { + int lastDigit = n % 10; + if (lastDigit == 5) + { + foundFive = true; + break; + } + n /= 10; + } + + if (foundFive) + { + cout << "yes"; + } + else + { + cout << "no"; + } + + +} \ No newline at end of file diff --git a/Sem. 03/DevidersCount_PrimalityCheck.cpp b/Sem. 03/DevidersCount_PrimalityCheck.cpp new file mode 100644 index 0000000..7584722 --- /dev/null +++ b/Sem. 03/DevidersCount_PrimalityCheck.cpp @@ -0,0 +1,29 @@ +#include + +using namespace std; + +int main() +{ + unsigned int n; //allways positive int + cin >> n; + + int divCount = 0; + + for (int i = 1; i <= n; i++) + { + if (n%i == 0) + divCount++; + } + cout << divCount; + if (divCount == 2) + { + cout << "Prime"; + } + else + { + cout << "Not a prime"; + } + + + +} \ No newline at end of file diff --git a/Sem. 03/GCD_solution1.cpp b/Sem. 03/GCD_solution1.cpp new file mode 100644 index 0000000..58ea35b --- /dev/null +++ b/Sem. 03/GCD_solution1.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; + +int main() +{ + int n, k; + + cin >> n >> k; + + if (n < k) //swap + { + int temp = n; + n = k; + k = temp; + } + + int devider = 1; + int result; + while (devider <= k) + { + if (n % devider == 0 && k % devider == 0) + { + result = devider; + } + devider++; + } + + cout << result; + + +} \ No newline at end of file diff --git a/Sem. 03/GCD_solution2.cpp b/Sem. 03/GCD_solution2.cpp new file mode 100644 index 0000000..ba06c89 --- /dev/null +++ b/Sem. 03/GCD_solution2.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +int main() +{ + int n, k; + + cin >> n >> k; + + if (n < k) //swap + { + int temp = n; + n = k; + k = temp; + + } + int devider = k; + bool foundSolution = false; + + + while (!foundSolution) + { + if (n % devider == 0 && k % devider == 0) + foundSolution = true; + else + devider--; + + + } + cout << devider; + + + +} \ No newline at end of file diff --git a/Sem. 03/GCD_solution3_Eucid.cpp b/Sem. 03/GCD_solution3_Eucid.cpp new file mode 100644 index 0000000..f190a90 --- /dev/null +++ b/Sem. 03/GCD_solution3_Eucid.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() +{ + int n, k; + + cin >> n >> k; + + if (n < k) //swap + { + int temp = n; + n = k; + k = temp; + } + + while (k != 0) + { + int div = n % k; + n = k; + k = div; + } + cout << n << endl; +} \ No newline at end of file diff --git a/Sem. 03/PrintEvenNumbers.cpp b/Sem. 03/PrintEvenNumbers.cpp new file mode 100644 index 0000000..e9a2231 --- /dev/null +++ b/Sem. 03/PrintEvenNumbers.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + + int j = 0; + while (j <= n) + { + cout << j << endl; + j += 2; + } + + //Here the variable j is reachable! + + + for (int i = 0; i <=n; i++) + { + cout << i << endl; + } + // Here the variable i is NOT reachable. + + +} \ No newline at end of file diff --git a/Sem. 03/SumOfDigits.cpp b/Sem. 03/SumOfDigits.cpp new file mode 100644 index 0000000..6777a42 --- /dev/null +++ b/Sem. 03/SumOfDigits.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + + int digitSum = 0; + + while (n != 0) + { + int lastDigit = n % 10; //extracts last digit + digitSum += lastDigit; //adds it to the sum + n /= 10; //removes last digit + } + + cout << digitSum; + + +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/01. Between100and200.cpp b/Sem. 03/Tasks and Solutions/01. Between100and200.cpp new file mode 100644 index 0000000..0817bcc --- /dev/null +++ b/Sem. 03/Tasks and Solutions/01. Between100and200.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +int main() +{ + unsigned int n; + cin >> n; + + if (n < 100) + cout << "Less than 100" << endl; + else if (n <= 200) + cout << "Between 100 and 200" << endl; + else + cout << "More than 200" << endl; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/02. Speed check.cpp b/Sem. 03/Tasks and Solutions/02. Speed check.cpp new file mode 100644 index 0000000..4660382 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/02. Speed check.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + double speed; + cin >> speed; + + if (speed <= 10) + cout << "Slow" << endl; + else if (speed < 50) + cout << "Average" << endl; + else if (speed < 150) + cout << "Fast" << endl; + else if (speed < 1000) + cout << "Ultra fast" << endl; + else + cout << "Extremely fast" << endl; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/03. Figures.cpp b/Sem. 03/Tasks and Solutions/03. Figures.cpp new file mode 100644 index 0000000..170c403 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/03. Figures.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +const double PI = 3.14; +int main() +{ + char figure; + cin >> figure; + + if (figure == 's') + { + double side; + cin >> side; + cout << side * side << endl; + } + else if (figure == 'r') + { + double sideA, sideB; + cin >> sideA >> sideB; + cout << sideA * sideB << endl; + } + else if (figure == 'c') + { + double R; + cin >> R; + cout << PI * R * R << endl; + } +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/04. Time + 15.cpp b/Sem. 03/Tasks and Solutions/04. Time + 15.cpp new file mode 100644 index 0000000..aee3118 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/04. Time + 15.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +const double PI = 3.14; +int main() +{ + int hours, mins; + cin >> hours >> mins; + + (mins += 15) %= 60; + + if (mins < 15) + (hours+=1)%=24; + + if (hours <= 9) + cout << 0; + cout << hours << ":"; + if (mins <= 9) + cout << 0; + cout << mins << endl; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/05. Chainsaw.cpp b/Sem. 03/Tasks and Solutions/05. Chainsaw.cpp new file mode 100644 index 0000000..68940e0 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/05. Chainsaw.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() +{ + int a, b, c, d, e; + cin >> a >> b >> c >> d >> e; + + if ((a <= b && b >= c && c <= d && d >= e) + || (a >= b && b <= c && c >= d && d <= e)) + { + cout << "Yes"; + } + else + cout << "No"; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/06. DivBy3.cpp b/Sem. 03/Tasks and Solutions/06. DivBy3.cpp new file mode 100644 index 0000000..044aee9 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/06. DivBy3.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + for (int i = 3; i <= n; i+=3) + cout << i << endl; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/07. ContainsDigit.cpp b/Sem. 03/Tasks and Solutions/07. ContainsDigit.cpp new file mode 100644 index 0000000..4ae1131 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/07. ContainsDigit.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +int main() +{ + int n, searchedDigit; + cin >> n >> searchedDigit; + + bool found = false; + while (n != 0) + { + int lastDigit = n % 10; + if (searchedDigit == lastDigit) + { + found = true; + break; + } + n /= 10; + } +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/08. DuplicateDigits.cpp b/Sem. 03/Tasks and Solutions/08. DuplicateDigits.cpp new file mode 100644 index 0000000..0fa5946 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/08. DuplicateDigits.cpp @@ -0,0 +1,93 @@ +#include +using namespace std; + +int main() +{ + bool found0, found1, found2, found3, found4, found5, found6, found7, found8, found9; + found0 = found1 = found2 = found3 = found4 = found5 = found6 = found7 = found8 = found9 = false; + + int n; + cin >> n; + + bool foundDuplicate = false; + while (!foundDuplicate && n != 0) + { + int lastDigit = n % 10; + switch (lastDigit) + { + case 0: + if (found0) + { + foundDuplicate = true; + + } + found0 = true; + break; + case 1: + if (found1) + { + foundDuplicate = true; + } + found1 = true; + break; + case 2: + if (found2) + { + foundDuplicate = true; + } + found2 = true; + break; + case 3: + if (found3) + { + foundDuplicate = true; + } + found3 = true; + break; + case 4: + if (found4) + { + foundDuplicate = true; + } + found4 = true; + break; + case 5: + if (found5) + { + foundDuplicate = true; + } + found5 = true; + break; + case 6: + if (found6) + { + foundDuplicate = true; + } + found6 = true; + break; + case 7: + if (found7) + { + foundDuplicate = true; + } + found7 = true; + break; + case 8: + if (found8) + { + foundDuplicate = true; + } + found8 = true; + case 9: + if (found9) + { + foundDuplicate = true; + } + found9 = true; + break; + } + n /= 10; + } + + cout << foundDuplicate; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/09. SumFromKtoN.cpp b/Sem. 03/Tasks and Solutions/09. SumFromKtoN.cpp new file mode 100644 index 0000000..aea318a --- /dev/null +++ b/Sem. 03/Tasks and Solutions/09. SumFromKtoN.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main() +{ + int n, k; + cin >> k >> n; + + int sum = 0; + for (int i = k; i <= n; i++) + sum += i; + + cout << sum << endl; + + //or use the formula + + cout << (n*(n + 1)) / 2 - ((k - 1)*k) / 2 << endl; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/10. Pyramid.cpp b/Sem. 03/Tasks and Solutions/10. Pyramid.cpp new file mode 100644 index 0000000..5d9e2a9 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/10. Pyramid.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= i; j++) + cout << "$"; + cout << endl; + } +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/11. Clock.cpp b/Sem. 03/Tasks and Solutions/11. Clock.cpp new file mode 100644 index 0000000..6386ca0 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/11. Clock.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main() +{ + for (int hour = 0; hour <= 23; hour++) + { + for (int min = 0; min <= 59; min++) + { + if (hour < 10) + cout << 0; + cout << hour << ":"; + if (min < 10) + cout << 0; + cout << min << endl; + } + } +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/12. ClockWithStart.cpp b/Sem. 03/Tasks and Solutions/12. ClockWithStart.cpp new file mode 100644 index 0000000..1b996e1 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/12. ClockWithStart.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main() +{ + int h, m; + cin >> h >> m; + + for (int min = m + 1; min <= 59; min++) + { + if (h < 10) + cout << 0; + cout << h << ":"; + if (min < 10) + cout << 0; + cout << min << endl; + } + + for (int hour = h+1; hour <= 23; hour++) + { + for (int min = 0; min <= 59; min++) + { + if (hour < 10) + cout << 0; + cout << hour << ":"; + if (min < 10) + cout << 0; + cout << min << endl; + } + } +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/13. ClockWithStartAndEnd.cpp b/Sem. 03/Tasks and Solutions/13. ClockWithStartAndEnd.cpp new file mode 100644 index 0000000..af39745 --- /dev/null +++ b/Sem. 03/Tasks and Solutions/13. ClockWithStartAndEnd.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; + +int main() +{ + int hStart, mStart, hEnd, mEnd; + cin >> hStart >> mStart >> hEnd >> mEnd; + + for (int min = mStart + 1; min <= 59; min++) + { + if (hStart < 10) + cout << 0; + cout << hStart << ":"; + if (min < 10) + cout << 0; + cout << min << endl; + } + + for (int hour = hStart+1; hour <= hEnd-1; hour++) + { + for (int min = 0; min <= 59; min++) + { + if (hour < 10) + cout << 0; + cout << hour << ":"; + if (min < 10) + cout << 0; + cout << min << endl; + } + } + + for (int min = 0; min < mEnd; min++) + { + if (hEnd < 10) + cout << 0; + cout << hEnd << ":"; + if (min < 10) + cout << 0; + cout << min << endl; + } +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/14. Frame.cpp b/Sem. 03/Tasks and Solutions/14. Frame.cpp new file mode 100644 index 0000000..92de3ca --- /dev/null +++ b/Sem. 03/Tasks and Solutions/14. Frame.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + //Ãîðíà ðàìêà + cout << '+'; + for (int i = 0; i < n - 2; i++) + cout << '-'; + cout << '+' << endl; + + + //Ñðåäà + for (int j = 0; j < n - 2; j++) + { + cout << '|'; + for (int i = 0; i < n - 2; i++) + cout << '-'; + cout << '|' << endl; + } + + //Äîëíà ðàìêà + cout << '+'; + for (int i = 0; i < n - 2; i++) + cout << '-'; + cout << '+' << endl; +} \ No newline at end of file diff --git a/Sem. 03/Tasks and Solutions/tasks.pdf b/Sem. 03/Tasks and Solutions/tasks.pdf new file mode 100644 index 0000000..6c2ad50 Binary files /dev/null and b/Sem. 03/Tasks and Solutions/tasks.pdf differ diff --git a/Sem. 04/README.md b/Sem. 04/README.md new file mode 100644 index 0000000..9ce9f75 --- /dev/null +++ b/Sem. 04/README.md @@ -0,0 +1,129 @@ +**Десетична бройна система.** + +1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 , 12 + +Защото използваме 10 символа: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + +Най-малката бройна система: **Единична бройна система (Unary)** + +Символи: 1 + +1 = 1 + +2 = 11 + +3 = 111 + +4 = 1111 + +5 = 11111 + +6 = 111111 + + +**Двоична бройна система (binary)** + +Символи: 0,1 + +0 - 00000 + +1 - 00001 + +2 - 00010 + +3 - 00011 + +4 - 00100 + +5 - 00101 + +6 - 00110 + +**Троична бройна система** + +Символи: 0, 1, 2 + +0 - 00 + +1 - 01 + +2 - 02 + +3 - 10 + +4 - 11 + +5 - 12 + +6 - 20 + + +Пребобрзвуане между бройни системи. + +**1. Десетична бройна система -> k-ична(k = 2(двоична), k = 3(троична), k = 10(десетична)) бройна система.** + +**Пример 1**: Преобразуване на числото 36 от десетична бройна система в двоична бройна система. + +Т.е k = 2. + +| | | %k | +|----|--------|----| +| | n = 36 | 0 | +| /k | 18 | 0 | +| /k | 9 | 1 | +| /k | 4 | 0 | +| /k | 2 | 0 | +| /k | 1 | 1 | +| /k | 0 | | + + +**Гледаме от долу нагоре - 100100** + +**Пример 2**: Преобразуване на числото 38 от десетична бройна система в троична бройна система. + +Т.е k = 3. + +| | | %k | +|----|--------|----| +| | n = 38 | 2 | +| /k | 12 | 0 | +| /k | 4 | 1 | +| /k | 1 | 1 | +| /k | 0 | | + +**Гледаме от долу нагоре - 1102** + +**1. k-ична бройна система -> десетична бройна система.** + +**Пример 3**: Преобразуване на числото 100100 от двоична бройна система в десетична бройна система. + +0*2^0 + 0*2^1 + 1*2^2 + 0*2^3 + 0*2^4 + 1*2^5 = 4 + 32 = 36 + +**Пример 4**: Преобразуване на числото 1102 от троична бройна система в десетична бройна система + +2*3^0 + 0*3^1 + 1*3^2 + 1*3^3 = 2 + 9 + 27 = 38. + + +Всяка една променлива има **фиксиран** размер - памет, която заема. + +int - 32 бита. бит - 0 или 1 + +sizeof(int) - > 4 размер в байтове. Байт = 8 бита. + +Първият бит в int-а определя знака. + +Минимална стойност на променлива от тип int: -2^31. + +Максимална стоиност на променлива от тип int: 2^31 - 1 + +Побитови операции: Виж **bitwise_examples.cpp** + +Побитови операции(задачи): + +**Задача 1**: Да се провери дали дадено число е четно или нечетно. + +**Задача 2**: Въвежда се числa n и k и да се определи стойността на k-тия бит.(Вход: 10, 2 (000..001010) Изход: 0) + +**Задача 3**: Въвежда се число n. Да се пресметне 2^n. + +**Задача 4**: Въвежда се число n. Да се пресметне числото закодирано в предпоследните 3 бита. diff --git a/Sem. 04/Task1.cpp b/Sem. 04/Task1.cpp new file mode 100644 index 0000000..78ea86d --- /dev/null +++ b/Sem. 04/Task1.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + if (n & 1 == 1) + cout << "Odd"; + else + cout << "Even"; + +} \ No newline at end of file diff --git a/Sem. 04/Task2.cpp b/Sem. 04/Task2.cpp new file mode 100644 index 0000000..a45a2e6 --- /dev/null +++ b/Sem. 04/Task2.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() +{ + int n, k; + cin >> n >> k; + + int temp = 1; + temp = temp << k; + + if ((n & temp) == 0) + cout << "0"; + else + cout << "1"; + +} \ No newline at end of file diff --git a/Sem. 04/Task3.cpp b/Sem. 04/Task3.cpp new file mode 100644 index 0000000..6e71c31 --- /dev/null +++ b/Sem. 04/Task3.cpp @@ -0,0 +1,10 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + cout << (1 << n); +} \ No newline at end of file diff --git a/Sem. 04/Task4.cpp b/Sem. 04/Task4.cpp new file mode 100644 index 0000000..b0f5c04 --- /dev/null +++ b/Sem. 04/Task4.cpp @@ -0,0 +1,10 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + // 14 = 000...001110 - òàêà ñ "ïîáèòîâî è" ùå âçåìåì ñàìî òåçè 3 áèòà, à îñòàíàëèòå ùå áúäàò 0. Ïîñëå ãè ïðåìåñòâàìå äî íà÷àëîòî (èçïîëçâàéêè >>). + cout << ((n & 14) >> 1); +} \ No newline at end of file diff --git a/Sem. 04/bitwise_examples.cpp b/Sem. 04/bitwise_examples.cpp new file mode 100644 index 0000000..5dd5684 --- /dev/null +++ b/Sem. 04/bitwise_examples.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +int main() +{ + int a = 13; // 000...01101 + int b = 20; // 000...10100 + + int r1 = a & b; // 000...00100(4) + int r2 = a | b; // 000...11101(29) + int r3 = a ^ b; // 000...11001(25) + int r4 = a >> 1;// 000...00110(6) + int r5 = b << 1;// 000..101000(40) + + std::cout << r1 << endl; + std::cout << r2 << endl; + std::cout << r3 << endl; + std::cout << r4 << endl; + std::cout << r5 << endl; +} diff --git a/Sem. 05/README.md b/Sem. 05/README.md new file mode 100644 index 0000000..b65599b --- /dev/null +++ b/Sem. 05/README.md @@ -0,0 +1,18 @@ +**Задача 1:** Въвежда се неотрицателно число n. Да се провери дали n е просто. + +**Задача 2:** Въвежда се неотрицателно число n. Да се отпечата неговото разбиване на прости множители. + +*Вход: 288, Изход: 2^5 * 3^2* + +**Задача 3:** Въвежда се неотрицателно число n. Пресметнете n + 1, използвайки само цикли и побитови операции. + +**Задача 4:** Въвеждат се неотрицателни числа n и k. Пресметнете n + k, използвайки само цикли и побитови операции. + +**Задача 5:** Въвеждат се неотрицателни числа n и k. Пресметнете n * k, използвайки само цикли и побитови операции. + +**Задача 6:** Всяко естествено число се представя по единствен начин като сума на **различни**(не се повтарят) степени на двойката. +Въвежда се естествено число n. Отпечатайте това разбиване на n. + +*Вход: 26, Изход: 2^1 + 2^3 + 2^4* + +*Вход: 15, Изход: 2^0 + 2^1 + 2^2 + 2^3* diff --git a/Sem. 05/Task 1.cpp b/Sem. 05/Task 1.cpp new file mode 100644 index 0000000..20ca708 --- /dev/null +++ b/Sem. 05/Task 1.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; + +int main() +{ + unsigned int n; + cin >> n; + + //Ðåøåíèå 1: + bool isPrime1 = true; + for (int i = 2; i <= n - 1; i++) + { + if (n % i == 0) + isPrime1 = false; + } + cout << isPrime1 << endl; + // Ðåøåíèåòî ðàáîòè. Íî ïðàâè èçëèøíè ïðîâåðêè. Íå å íåîáõîäèìî äà òúðñèì äåëèòåë ÷àê äî n-1. + // Àêî íå íàìåðèì äåëèòåë îò êîðåí(n), òî íÿìà äà íàìåðèì è ñëåä êîðåíà. + + //Ðåøåíèå 2: + bool isPrime2 = true; + for (int i = 2; i <= sqrt(n); i++) + { + if (n % i == 0) + isPrime2 = false; + } + cout << isPrime2 << endl; + + // Ðåøåíèåòî ïàê ðàáîòè. Íî íà âñÿêà ïðîâåðêà i <= sqrt(n) ïðåñìÿòàìå êîðåí(n), êîåòî å î÷åâèäíî, ÷å å èçëèøíî. + // Ìîæå äà ãî ñìåòíåì âåäíúæ è ïîñëå äà ãî ïîëçâàìå. + + //Ðåøåíèå 3: + bool isPrime3 = true; + double temp = sqrt(n); + for (int i = 2; i <= temp; i++) + { + if (n % i == 0) + isPrime3 = false; + } + cout << isPrime3 << endl; + + // È òîâà ðåøåíèå äàâà âåðåí ðåçóëòàò. Íî îòíîâî å âúçìîæíî äà ïðàâè èçëèøíè ïðîâåðêè. + // Ïðè âúâåæäàíå íà ÷èñëîòî 2000000, î÷åâèäíî áè áèëî, ÷å ÷èñëîòî ÍÅ å ïðîñòî, ïîíåæå ñå äåëè íà 2. + // Íî íàøåòî ðåøåíèå ùå ïðîäúëæè äà òúðñè äåëèòåëè, äîðè ñëåä êàòî å âèäÿëî, ÷å èìà òàêúâ (â ñëó÷àÿ ÷èñëîòî 2). + + //Ôèíàëíî ðåøåíèå: + bool isPrime4 = true; + double temp2 = sqrt(n); + for (int i = 2; i <= temp2; i++) + { + if (n % i == 0) + { + isPrime4 = false; + break; + } + } + cout << isPrime4 << endl; +} \ No newline at end of file diff --git a/Sem. 05/Task 2.cpp b/Sem. 05/Task 2.cpp new file mode 100644 index 0000000..0f4408d --- /dev/null +++ b/Sem. 05/Task 2.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + +int main() +{ + unsigned int n; + cin >> n; + + for (int i = 2; n != 1; i++) //Âñè÷êè âúçìîæíè äåëèòåëè (ìíîæèòåëè) íà n 2,3,4,5,..., + { + // Ïðîâåðÿâàìå äàëè ÷èñëîòî å ïðîñòî (ïîíåæå íè èíòåðåñóâàò ñàìî ïðîñòè ìíîæèòåëè) + bool isPrime = true; + double temp = sqrt(i); + for (int j = 2; j <= temp; j++) + { + if (i % j == 0) + { + isPrime = false; + break; + } + } + + if (!isPrime) + continue; //Àêî íå å ïðîñòî - íå íè èíòåðåñóâà òîâà ÷èñëî. Ïðåìèíàâàìå êúì ñëåäâàùîòî. + + // Ùîì ñìå ñòèãíàëè òóê, ñìå óáåäåíè, ÷å i å ïðîñòî ÷èñëî. + // Èñêàìå äà âèäèì êîëêî ïúòè i äåëè n. + + int pow = 0; + while (n % i == 0) + { + n /= i; + pow++; + } + + if (pow != 0) //Àêî ïîíå âåäíúæ ãî å ðàçäåëèëî - çíà÷è ó÷àñòâà â ðàçáèâàíåòî íà ïðîñòè ìíîæèòåëè. + cout << i << "^" << pow << " "; + } +} \ No newline at end of file diff --git a/Sem. 05/Task 3.cpp b/Sem. 05/Task 3.cpp new file mode 100644 index 0000000..6723ee2 --- /dev/null +++ b/Sem. 05/Task 3.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + + +//Àëãîðèòúìúò çà ñúáèðàíå ñ 1 â äâîè÷åí çàïèñ: +//Îò äÿñíî íà ëÿâî - ïðàâèì âñè÷êè 1-öè íà 0, äîêàòî íå ñðåùíåì ïúðâàòà 0. +//Ïúðâàòà 0 ÿ ïðàâèì íà 1. + +// 101001111 + 1 +// 101010000 +int main() +{ + unsigned int n; + cin >> n; + + int mask = 1; //Íàé-äåñíèÿò áèò íà ìàñêàòà å 1-öà. Âñè÷êè äðóãè ñà 0-ëè. + + + while ((n & mask) > 0) //Ïðîâåðÿâàìå äàëè òåêóùèÿ áèò å 1-öà. (ïðè ïúðâîòî âëèçàíå, ïðîâåðÿâàìå íàé-äåñíèÿ) + { + n ^= mask; // Ïðàâèì ãî íà 0 ( n = n ^ mask) + mask <<= 1; // Îòìåñòâàìå ìàñêàòà, çà äà ïðîâåðèì áèò-à â ëÿâî. (mask = mask << 1) + } + + //Îòêðèëè ñìå ïúðâàòà 0. 1-öàòà å íà òî÷íàòà ïîçèöèÿ â ìàñêàòà. + n |= mask; // Ïðàâèì íà 1-öa (n = n | mask) +} \ No newline at end of file diff --git a/Sem. 05/Task 4.cpp b/Sem. 05/Task 4.cpp new file mode 100644 index 0000000..6d57f92 --- /dev/null +++ b/Sem. 05/Task 4.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; + +int main() +{ + unsigned int n, k; + cin >> n >> k; + + + //Изпълняваме k пъти събирането на n с 1 + for (int i = 0; i < k; i++) + { + //Събираме n с 1-ца (кодът от миналата задача) + int mask = 1; + while ((n & mask) > 0) + { + n ^= mask; + mask <<= 1; + } + n |= mask; + } + cout << n << endl; +} diff --git a/Sem. 05/Task 5.cpp b/Sem. 05/Task 5.cpp new file mode 100644 index 0000000..6f3d0dd --- /dev/null +++ b/Sem. 05/Task 5.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main() +{ + unsigned int n, k; + cin >> n >> k; + + //Ñìÿòàìå n*k. n+n+n...+n (k ïúòè). + //Ïðèëàãàìå êîäà îò ïðåäèøíàòà çàäà÷à k ïúòè + + + int result = 0; + + //Събирането с n го правим k пъти. Т.е става точно n*k + for (int t = 0; t < k; t++) + { + + //Събирането с 1 го правим пъти. Т.е става +n + for (int i = 0; i < n; i++) + { + //Събираме n с 1. + int mask = 1; + while ((result & mask) > 0) + { + result ^= mask; + mask <<= 1; + } + result |= mask; + } + } + cout << result << endl; +} diff --git a/Sem. 05/Task 6.cpp b/Sem. 05/Task 6.cpp new file mode 100644 index 0000000..415cae4 --- /dev/null +++ b/Sem. 05/Task 6.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + unsigned int n; + cin >> n; + + int currentPosition = 0; + while (n != 0) + { + if (n % 2 == 1) //Проверяваме последния бит дали е 1. + { + cout << "2^" << currentPosition << " "; + } + currentPosition++; + n >>= 1; // Премахваме последния бит и предпоследния става последен (n /=2); + } +} diff --git a/Sem. 06/README.md b/Sem. 06/README.md new file mode 100644 index 0000000..e8c4d0b --- /dev/null +++ b/Sem. 06/README.md @@ -0,0 +1,35 @@ +**Задача 1:** Въвежда се неотрицателно число n. Да се отпечатат всички двойки прости числа, които са във вида 6k-1 и 6k+1. + +**Задача 2:** Напишете функция, която приема неотрицателно число n и връща числото обърнато + +*Вход: 288, Изход: 822* + +**Задача 3:** Напишете функция, която приема неотрицателно число и връща дали числото е палиндром. + +**Задача 4:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е суфикс на n. + +*Вход: 288, 88, Изход: true* + +**Задача 5:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е префикс на n. + +*Вход: 288, 28, Изход: true* + +**Задача 6:** Напишете функция, която приема неотрицателни числа n и k и връща дали k се съдържа в n. + +*Вход: 2831, 83, Изход: true* + +**Задача 7:** Напишете функция, която приема неотрицателно число n и проверява дали има 4 последователни еднакви цифри. + +*Вход: 28777731, 83, Изход: true* + +**Задача 8:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани във възходящ ред. + +*Вход: 122239, Изход: true* + +**Задача 9:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани в низходящ ред. + +*Вход: 99943, Изход: true* + +**Задача 10:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са еднакви. + +*Вход: 111111, Изход: true* diff --git a/Sem. 06/Task_1(with functions).cpp b/Sem. 06/Task_1(with functions).cpp new file mode 100644 index 0000000..db68d0d --- /dev/null +++ b/Sem. 06/Task_1(with functions).cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +bool isPrime(int number) +{ + double temp = sqrt(number); + for (int i = 2; i <= temp; i++) + { + if (number % i == 0) + return false; //Ñïèðà ôóíêöèÿòà è âðúùà îòãîâîð - ëúæà + } + return true; +} + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i <= n; i += 6) + { + if (isPrime(i - 1) && isPrime(i + 1)) + cout << i - 1 << " " << i + 1 << endl; + } + +} \ No newline at end of file diff --git a/Sem. 06/Task_1(without functions).cpp b/Sem. 06/Task_1(without functions).cpp new file mode 100644 index 0000000..9e5bcdb --- /dev/null +++ b/Sem. 06/Task_1(without functions).cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i <= n; i+=6) + { + int firstNumToCheck = i - 1, secondNumToCheck = i + 1; + + double temp = sqrt(firstNumToCheck); + bool isFirstNumPrime = true; + for (int j = 2; j <= temp; j++) + { + if (firstNumToCheck % j == 0) + { + isFirstNumPrime = false; + break; + } + } + + if (!isFirstNumPrime) + continue; + double temp2 = sqrt(secondNumToCheck); + bool isSecondNumPrime = true; + for (int j = 2; j <= temp2; j++) + { + if (secondNumToCheck % j == 0) + { + isSecondNumPrime = false; + break; + } + } + if (isSecondNumPrime) + cout << firstNumToCheck << " " << secondNumToCheck << endl; + } + +} \ No newline at end of file diff --git a/Sem. 06/Tasks_2,3,4,5,6,7,8,9,10.cpp b/Sem. 06/Tasks_2,3,4,5,6,7,8,9,10.cpp new file mode 100644 index 0000000..1d9666d --- /dev/null +++ b/Sem. 06/Tasks_2,3,4,5,6,7,8,9,10.cpp @@ -0,0 +1,108 @@ +#include +using namespace std; + + +//Task 2 +unsigned int reverse(unsigned int number) +{ + int result = 0; + + while (number != 0) + { + int lastDigit = number % 10; + (result *= 10) += lastDigit; + number /= 10; + } + + return result; +} + +//Task 3 +bool isPalindrome(unsigned int n) +{ + return n == reverse(n); +} + +//Task 4 +bool isSuffix(unsigned int n, unsigned int k) +{ + if (n < k) + return false; + while (k != 0) + { + int lastDigitFromN = n % 10; + int lastDigitFromK = k % 10; + if (lastDigitFromN != lastDigitFromK) + return false; + n /= 10; + k /= 10; + } + return true; +} + +// Task 5 +bool isPrefix(unsigned int n, unsigned int k) +{ + return isSuffix(reverse(n), reverse(k)); +} + +// Task 6 +bool isInfix(unsigned int n, unsigned int k) +{ + if (k > n) + return false; + while (n >= k) + { + if (isSuffix(n, k)) + return true; + n /= 10; + } + return false; +} + +// Task 7 +bool hasConsecutiveFourDigits(unsigned int n) +{ + for (int i = 1111; i <= 9999; i+=1111) + { + if (isInfix(n, i)) + return true; + } + for (int i = 10000; i <= 90000; i += 10000) + { + if (isInfix(n, i)) + return true; + } + return false; +} + +// Task 8 +bool areDigitsSortedIncreasing(unsigned int n) +{ + while (n >= 10) + { + int lastDigit = n % 10; + int lastLastDigit = (n / 10) % 10; + + if (lastLastDigit > lastDigit) + return false; + n /= 10; // + } + return true; +} + +// Task 9 +bool areDigitsSortedDecreasing(unsigned int n) +{ + return areDigitsSortedIncreasing(reverse(n)); +} + +// Task 10 +bool areAllDigitsTheSame(unsigned int n) +{ + return areDigitsSortedIncreasing(n) && areDigitsSortedDecreasing(n); +} +int main() +{ + cout << areAllDigitsTheSame(777); +} diff --git a/Sem. 07/BullsAndColls.cpp b/Sem. 07/BullsAndColls.cpp new file mode 100644 index 0000000..5b5a54e --- /dev/null +++ b/Sem. 07/BullsAndColls.cpp @@ -0,0 +1,100 @@ +#include +#include +using namespace std; + + +//Èãðàòà áèêîâå è êðàâè. +// Êîìï. ãåíåðèðà ñëó÷àéíî ÷èñëî âè èíòåðâàëà [1000...9999]. +// Íèå òðÿáâà äà ãî ïîçíàåì. + + +// 4278 - 1 áèê, 1 êðàâà (áèê - ÷èñëî è ïîçèöèÿòà), (êðàâà - ÷èñëîòî , íî è ïîçèöèÿòà) +// Ïîçíàâàì ÷èñëîòî, êîãàòî èìàì 4 áèêà + +bool hasDuplicateDigits(int n) ///1343 +{ + const int DIGITCOUNT = 10; + bool found[DIGITCOUNT]; + for (int i = 0; i < DIGITCOUNT; i++) + found[i] = false; + while (n != 0) + { + int lastDigit = n % 10; + if (found[lastDigit] == true) + return true; + else + found[lastDigit] = true; + n /= 10; + } + return false; +} + +void convertNumberToArr(int n, int arr[]) +{ + + for (int i = 3; i >= 0; i--) + { + arr[i] = n % 10; + n /= 10; + } + +} +int countBulls(int myNumber[], int compNumber[]) +{ + int bullsCount = 0; + for (int i = 0; i <= 3; i++) + { + if (myNumber[i] == compNumber[i]) + bullsCount++; + } + return bullsCount; +} +int countCows(int myNumber[], int compNumber[]) +{ + int cowsCount = 0; + + for (int i = 0; i <= 3; i++) + { + int myDigit = myNumber[i]; + for (int j = 0; j <= 3; j++) + { + if (j == i) // çà äà íå áðîèì áèêîâåòå + continue; + if (myDigit == compNumber[j]) + cowsCount++; + } + } + return cowsCount; +} +int main() +{ + int numberToGuess; + do + { + numberToGuess = 1000 + rand() % 9000; // [1000..9999] + } + while (hasDuplicateDigits(numberToGuess)); + + cout << "Computer has picked a number! Try to guess it!" <> myNumber; + int myNumberArr[4]; + convertNumberToArr(myNumber, myNumberArr); + + bullsCount = countBulls(myNumberArr, numberToGuessArr); + cowsCount = countCows(myNumberArr, numberToGuessArr); + + cout << "Bulls: " << bullsCount << " Cows:" << cowsCount << endl; + + + } while (bullsCount != 4); + + cout << "Success!" << endl; +} \ No newline at end of file diff --git a/Sem. 07/README.md b/Sem. 07/README.md new file mode 100644 index 0000000..2c6303a --- /dev/null +++ b/Sem. 07/README.md @@ -0,0 +1,9 @@ +### Код от семинарите по "Увод в програмирането" - спец. Компютърни науки, група 7 - зимен семестър 2020/2021 + + + - **Тема 1 (09.10.2020) :** Променливи. Типове променливи. Оператори. Преобразуване между типове. + - **Тема 2 (16.10.2020) :** Приоритет на операторите. Асоциативност. Условни провеки (if, switch) + - **Тема 3 (23.10.2020 и 28.10.2020) :** Жизнен цикъл на променливите. Оператори за цикъл(while, for). Оператор break. Задачи. + - **Тема 4 (04.11.2020) :** Бройни системи. Побитови операции. + - **Тема 5 (13.11.2020) :** Задачи за цикли и побитови операции. + - **Тема 6 (17.11.2020) :** Функции. \ No newline at end of file diff --git a/Sem. 08/README.md b/Sem. 08/README.md new file mode 100644 index 0000000..e8c4d0b --- /dev/null +++ b/Sem. 08/README.md @@ -0,0 +1,35 @@ +**Задача 1:** Въвежда се неотрицателно число n. Да се отпечатат всички двойки прости числа, които са във вида 6k-1 и 6k+1. + +**Задача 2:** Напишете функция, която приема неотрицателно число n и връща числото обърнато + +*Вход: 288, Изход: 822* + +**Задача 3:** Напишете функция, която приема неотрицателно число и връща дали числото е палиндром. + +**Задача 4:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е суфикс на n. + +*Вход: 288, 88, Изход: true* + +**Задача 5:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е префикс на n. + +*Вход: 288, 28, Изход: true* + +**Задача 6:** Напишете функция, която приема неотрицателни числа n и k и връща дали k се съдържа в n. + +*Вход: 2831, 83, Изход: true* + +**Задача 7:** Напишете функция, която приема неотрицателно число n и проверява дали има 4 последователни еднакви цифри. + +*Вход: 28777731, 83, Изход: true* + +**Задача 8:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани във възходящ ред. + +*Вход: 122239, Изход: true* + +**Задача 9:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани в низходящ ред. + +*Вход: 99943, Изход: true* + +**Задача 10:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са еднакви. + +*Вход: 111111, Изход: true* diff --git a/Sem. 08/task1.cpp b/Sem. 08/task1.cpp new file mode 100644 index 0000000..f993c7e --- /dev/null +++ b/Sem. 08/task1.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +const int SIZE = 32; + +int Convert(bool arr[SIZE]) +{ + int result = 0; + for (int i = 31; i >= 0; i--) + result += arr[i] * (1 << 31-i); + return result; +} +int main() +{ + bool arr[SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1 }; + cout << Convert(arr); +} \ No newline at end of file diff --git a/Sem. 08/task2.cpp b/Sem. 08/task2.cpp new file mode 100644 index 0000000..beb700d --- /dev/null +++ b/Sem. 08/task2.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; + +const int SIZE = 30; +int CountOccurrences(int arr[SIZE], int n, int el) +{ + int count = 0; + for (int i = 0; i < n; i++) + { + if (arr[i] == el) + count++; + } + return count; +} + +int GetLonlyNumber(int arr[SIZE], int n) +{ + for (int i = 0; i < n; i++) + { + if (CountOccurrences(arr, n, arr[i]) == 1) + return arr[i]; + } + return -1; + +} + +int GetLonlyNumberBetter(int arr[SIZE], int n) +{ + int res = 0; + for (int i = 0; i < n; i++) + res ^= arr[i]; + return res; +} + +int main() +{ + int arr[SIZE]; + int n; + for (int i = 0; i < n; i++) + cin >> arr[i]; + cout << GetLonlyNumberBetter(arr, n); +} \ No newline at end of file diff --git a/Sem. 08/task3.cpp b/Sem. 08/task3.cpp new file mode 100644 index 0000000..6d7d209 --- /dev/null +++ b/Sem. 08/task3.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +const int SIZE = 30; +bool isSubarrayPalindrome(int arr[SIZE], int startIndex, int endIndex) +{ + while (startIndex < endIndex) + { + if (arr[startIndex] != arr[endIndex]) + return false; + startIndex++; + endIndex--; + } + return true; +} +void print(int arr[SIZE]) +{ + for (int i = 0; i < SIZE; i++) + cout << arr[i]; + cout << endl; +} + +int LongestPalindromicSubarray(int arr[SIZE], int n) +{ + int currentSize = n; + + int startIndex = 0; + int endIndex = startIndex + currentSize-1; + while (true) + { + if (isSubarrayPalindrome(arr, startIndex, endIndex)) + return endIndex - startIndex + 1; + startIndex++; + endIndex++; + if (endIndex == n)//last iteration + { + currentSize--; + startIndex = 0; + endIndex = startIndex + currentSize - 1; + } + } +} +int main() +{ + + int arr[SIZE] = {1,4,3,2,3}; + cout << LongestPalindromicSubarray(arr, 5); + +} diff --git a/Sem. 1/Variables.cpp b/Sem. 1/Variables.cpp deleted file mode 100644 index f793a65..0000000 --- a/Sem. 1/Variables.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -using namespace std; - - -int main() -{ - //The reason why operator = returns a value! - int a, b, c, d, e, f; - a = b = c = d = e = f = 5; - - //Types - int t1 = 4; - double t2 = 4.5; - char t3 = 'v'; - bool t4 = true; - - - //Operators - - //Arithmetic operators - int num1 = 5; - int num2 = 2; - - int result = a + b; //7 - result = a - b; //3 - result = a * b; //10 - result = a / b; // 2 (not 2.5) (both are ints) - result = a%b; //1 5:2 = 2 (rem :1) - - double num2Copy = 2; - double resultCopy = num1 / num2Copy; //2.5 (one of the variables is a double) - - int A = 5; - int B = 2; - - cout << (A++ - B) << endl;// 3 (but A becomes 6) - A = 5;//let's make it 5 again - cout << (++A - B) << endl;//4 (A becomes 6) - - // Comparison operators - - int N1 = 5; - int N2 = 6; - - cout << (N1 > N2)< N2; - cout << cond; - - - //Other comparison operators : ==, !=, >, <, >=,<= - - - - //Logical operators - - bool var1 = false; - bool var2 = true; - - bool t1 = var1 && var2; //false; - bool t2 = var1 || var2; //true - bool t3 = var1 ^ var2; //true - - - //Type casting - - int a1 = 97; - double b1 = a1; - char c1 = a1; - bool d1 = a1; - - cout << a1 << endl; //97 - cout << b1 << endl; //97.0 - cout << c1 << endl; //a - cout << d1 << endl; //1 - - - double b2 = 65.5; - int a2 = b2; - char c2 = b2; - bool d2 = b2; - - cout << b2 << endl; //65.5 - cout << a2 << endl; //65 - cout << c2 << endl; //A - cout << d2 << endl; //1 - - - char c3 = 'a'; - double b3 = c3; - int a3 = c3; - bool d3 = c3; - - cout << c3 << endl; //a - cout << b3 << endl; //97 - cout << a3 << endl; //97 - cout << d3 << endl; //1 - - bool d4 = true; - int a4 = d4; - double b4 = d4; - char c4 = d4; - - cout << c4 << endl; // ?? - cout << b4 << endl; // 1 - cout << a4 << endl; // 1 - cout << d4 << endl; // 1 - - int grade = 5; - - bool isValid = grade >= 2 && grade <= 6; - bool isValid2 = grade == 2 || grade == 3 || grade == 4 || grade == 5||grade == 6; - - bool isNotValid = !isValid; - bool isNotValid2 = grade < 2 || grade>6; - -} diff --git a/Sem. 2/Even_Odd.cpp b/Sem. 2/Even_Odd.cpp deleted file mode 100644 index 89c2ecd..0000000 --- a/Sem. 2/Even_Odd.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; - -int main() -{ - int number; - cin >> number; - - if (number % 2 == 0) - { - std::cout << "Even" << endl; - } - else - { - std::cout << "Odd" << endl; - } -} \ No newline at end of file diff --git a/Sem. 2/Grades.cpp b/Sem. 2/Grades.cpp deleted file mode 100644 index 18e1538..0000000 --- a/Sem. 2/Grades.cpp +++ /dev/null @@ -1,63 +0,0 @@ - -#include -using namespace std; - -int main() -{ - int grade; - cin >> grade; - - //Bad - if (grade == 2) - { - cout << "Poor" << endl; - } - if (grade == 3) - { - cout << "Average" << endl; - } - if (grade == 4) - { - cout << "Good" << endl; - } - if (grade == 5) - { - cout << "Very good" << endl; - } - if (grade == 6) - { - cout << "Excellent" << endl; - } - if (grade < 2 || grade > 6) - { - cout << "Invalid" << endl; - } - //This works! But when we find a match, we continue checking, even though we don't need to. - - //Better - if (grade == 2) - { - cout << "Poor" << endl; - } - else if (grade == 3) - { - cout << "Average" << endl; - } - else if (grade == 4) - { - cout << "Good" << endl; - } - else if (grade == 5) - { - cout << "Very good" << endl; - } - else if (grade == 6) - { - cout << "Excellent" << endl; - } - else - { - cout << "Invalid" << endl; - } - -} \ No newline at end of file diff --git a/Sem. 2/Operators_priority.png b/Sem. 2/Operators_priority.png deleted file mode 100644 index 07d2565..0000000 Binary files a/Sem. 2/Operators_priority.png and /dev/null differ diff --git a/Sem. 2/dayOfWeek.cpp b/Sem. 2/dayOfWeek.cpp deleted file mode 100644 index b9640c3..0000000 --- a/Sem. 2/dayOfWeek.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -using namespace std; - -int main() -{ - int num; - cin >> num; - - switch (num) - { - case 1:cout << "Monday" << endl; break; - case 2:cout << "Tuesday" << endl; break; - case 3:cout << "Wednesday" << endl; break; - case 4:cout << "Thursday" << endl; break; - case 5:cout << "Friday" << endl; break; - case 6:cout << "Saturday" << endl; break; - case 7:cout << "Sunday" << endl; break; - - default: cout << "The number is not a valid day of the week" << endl; - } - -} \ No newline at end of file diff --git a/Sem. 2/isPrime_between[1,9].cpp b/Sem. 2/isPrime_between[1,9].cpp deleted file mode 100644 index 08d8445..0000000 --- a/Sem. 2/isPrime_between[1,9].cpp +++ /dev/null @@ -1,26 +0,0 @@ - -#include -using namespace std; - -int main() -{ - int num; - cin >> num; - - switch (num) - { - case 2: - case 3: - case 5: - case 7:cout << "Prime" << endl; break; - - case 1: - case 4: - case 6: - case 8: - case 9:cout << "Not a prime" << endl; break; - - default: cout << "The number is not between 1 and 10" << endl; break; - } - -} \ No newline at end of file diff --git a/Sem. 3/Contains5.cpp b/Sem. 3/Contains5.cpp deleted file mode 100644 index 78d13f0..0000000 --- a/Sem. 3/Contains5.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n; - cin >> n; - - bool foundFive = false; - while (n != 0) - { - int lastDigit = n % 10; - if (lastDigit == 5) - { - foundFive = true; - break; - } - n /= 10; - } - - if (foundFive) - { - cout << "yes"; - } - else - { - cout << "no"; - } - - -} \ No newline at end of file diff --git a/Sem. 3/DevidersCount_PrimalityCheck.cpp b/Sem. 3/DevidersCount_PrimalityCheck.cpp deleted file mode 100644 index 7584722..0000000 --- a/Sem. 3/DevidersCount_PrimalityCheck.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -using namespace std; - -int main() -{ - unsigned int n; //allways positive int - cin >> n; - - int divCount = 0; - - for (int i = 1; i <= n; i++) - { - if (n%i == 0) - divCount++; - } - cout << divCount; - if (divCount == 2) - { - cout << "Prime"; - } - else - { - cout << "Not a prime"; - } - - - -} \ No newline at end of file diff --git a/Sem. 3/GCD_solution1.cpp b/Sem. 3/GCD_solution1.cpp deleted file mode 100644 index 58ea35b..0000000 --- a/Sem. 3/GCD_solution1.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n, k; - - cin >> n >> k; - - if (n < k) //swap - { - int temp = n; - n = k; - k = temp; - } - - int devider = 1; - int result; - while (devider <= k) - { - if (n % devider == 0 && k % devider == 0) - { - result = devider; - } - devider++; - } - - cout << result; - - -} \ No newline at end of file diff --git a/Sem. 3/GCD_solution2.cpp b/Sem. 3/GCD_solution2.cpp deleted file mode 100644 index ba06c89..0000000 --- a/Sem. 3/GCD_solution2.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n, k; - - cin >> n >> k; - - if (n < k) //swap - { - int temp = n; - n = k; - k = temp; - - } - int devider = k; - bool foundSolution = false; - - - while (!foundSolution) - { - if (n % devider == 0 && k % devider == 0) - foundSolution = true; - else - devider--; - - - } - cout << devider; - - - -} \ No newline at end of file diff --git a/Sem. 3/GCD_solution3_Eucid.cpp b/Sem. 3/GCD_solution3_Eucid.cpp deleted file mode 100644 index f190a90..0000000 --- a/Sem. 3/GCD_solution3_Eucid.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n, k; - - cin >> n >> k; - - if (n < k) //swap - { - int temp = n; - n = k; - k = temp; - } - - while (k != 0) - { - int div = n % k; - n = k; - k = div; - } - cout << n << endl; -} \ No newline at end of file diff --git a/Sem. 3/PrintEvenNumbers.cpp b/Sem. 3/PrintEvenNumbers.cpp deleted file mode 100644 index e9a2231..0000000 --- a/Sem. 3/PrintEvenNumbers.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n; - cin >> n; - - int j = 0; - while (j <= n) - { - cout << j << endl; - j += 2; - } - - //Here the variable j is reachable! - - - for (int i = 0; i <=n; i++) - { - cout << i << endl; - } - // Here the variable i is NOT reachable. - - -} \ No newline at end of file diff --git a/Sem. 3/SumOfDigits.cpp b/Sem. 3/SumOfDigits.cpp deleted file mode 100644 index 6777a42..0000000 --- a/Sem. 3/SumOfDigits.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n; - cin >> n; - - int digitSum = 0; - - while (n != 0) - { - int lastDigit = n % 10; //extracts last digit - digitSum += lastDigit; //adds it to the sum - n /= 10; //removes last digit - } - - cout << digitSum; - - -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/01. Between100and200.cpp b/Sem. 3/Tasks and Solutions/01. Between100and200.cpp deleted file mode 100644 index 0817bcc..0000000 --- a/Sem. 3/Tasks and Solutions/01. Between100and200.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -using namespace std; - -int main() -{ - unsigned int n; - cin >> n; - - if (n < 100) - cout << "Less than 100" << endl; - else if (n <= 200) - cout << "Between 100 and 200" << endl; - else - cout << "More than 200" << endl; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/02. Speed check.cpp b/Sem. 3/Tasks and Solutions/02. Speed check.cpp deleted file mode 100644 index 4660382..0000000 --- a/Sem. 3/Tasks and Solutions/02. Speed check.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -using namespace std; - -int main() -{ - double speed; - cin >> speed; - - if (speed <= 10) - cout << "Slow" << endl; - else if (speed < 50) - cout << "Average" << endl; - else if (speed < 150) - cout << "Fast" << endl; - else if (speed < 1000) - cout << "Ultra fast" << endl; - else - cout << "Extremely fast" << endl; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/03. Figures.cpp b/Sem. 3/Tasks and Solutions/03. Figures.cpp deleted file mode 100644 index 170c403..0000000 --- a/Sem. 3/Tasks and Solutions/03. Figures.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace std; - -const double PI = 3.14; -int main() -{ - char figure; - cin >> figure; - - if (figure == 's') - { - double side; - cin >> side; - cout << side * side << endl; - } - else if (figure == 'r') - { - double sideA, sideB; - cin >> sideA >> sideB; - cout << sideA * sideB << endl; - } - else if (figure == 'c') - { - double R; - cin >> R; - cout << PI * R * R << endl; - } -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/04. Time + 15.cpp b/Sem. 3/Tasks and Solutions/04. Time + 15.cpp deleted file mode 100644 index aee3118..0000000 --- a/Sem. 3/Tasks and Solutions/04. Time + 15.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -using namespace std; - -const double PI = 3.14; -int main() -{ - int hours, mins; - cin >> hours >> mins; - - (mins += 15) %= 60; - - if (mins < 15) - (hours+=1)%=24; - - if (hours <= 9) - cout << 0; - cout << hours << ":"; - if (mins <= 9) - cout << 0; - cout << mins << endl; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/05. Chainsaw.cpp b/Sem. 3/Tasks and Solutions/05. Chainsaw.cpp deleted file mode 100644 index 68940e0..0000000 --- a/Sem. 3/Tasks and Solutions/05. Chainsaw.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; - -int main() -{ - int a, b, c, d, e; - cin >> a >> b >> c >> d >> e; - - if ((a <= b && b >= c && c <= d && d >= e) - || (a >= b && b <= c && c >= d && d <= e)) - { - cout << "Yes"; - } - else - cout << "No"; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/06. DivBy3.cpp b/Sem. 3/Tasks and Solutions/06. DivBy3.cpp deleted file mode 100644 index 044aee9..0000000 --- a/Sem. 3/Tasks and Solutions/06. DivBy3.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - - for (int i = 3; i <= n; i+=3) - cout << i << endl; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/07. ContainsDigit.cpp b/Sem. 3/Tasks and Solutions/07. ContainsDigit.cpp deleted file mode 100644 index 4ae1131..0000000 --- a/Sem. 3/Tasks and Solutions/07. ContainsDigit.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n, searchedDigit; - cin >> n >> searchedDigit; - - bool found = false; - while (n != 0) - { - int lastDigit = n % 10; - if (searchedDigit == lastDigit) - { - found = true; - break; - } - n /= 10; - } -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/08. DuplicateDigits.cpp b/Sem. 3/Tasks and Solutions/08. DuplicateDigits.cpp deleted file mode 100644 index 0fa5946..0000000 --- a/Sem. 3/Tasks and Solutions/08. DuplicateDigits.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -using namespace std; - -int main() -{ - bool found0, found1, found2, found3, found4, found5, found6, found7, found8, found9; - found0 = found1 = found2 = found3 = found4 = found5 = found6 = found7 = found8 = found9 = false; - - int n; - cin >> n; - - bool foundDuplicate = false; - while (!foundDuplicate && n != 0) - { - int lastDigit = n % 10; - switch (lastDigit) - { - case 0: - if (found0) - { - foundDuplicate = true; - - } - found0 = true; - break; - case 1: - if (found1) - { - foundDuplicate = true; - } - found1 = true; - break; - case 2: - if (found2) - { - foundDuplicate = true; - } - found2 = true; - break; - case 3: - if (found3) - { - foundDuplicate = true; - } - found3 = true; - break; - case 4: - if (found4) - { - foundDuplicate = true; - } - found4 = true; - break; - case 5: - if (found5) - { - foundDuplicate = true; - } - found5 = true; - break; - case 6: - if (found6) - { - foundDuplicate = true; - } - found6 = true; - break; - case 7: - if (found7) - { - foundDuplicate = true; - } - found7 = true; - break; - case 8: - if (found8) - { - foundDuplicate = true; - } - found8 = true; - case 9: - if (found9) - { - foundDuplicate = true; - } - found9 = true; - break; - } - n /= 10; - } - - cout << foundDuplicate; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/09. SumFromKtoN.cpp b/Sem. 3/Tasks and Solutions/09. SumFromKtoN.cpp deleted file mode 100644 index aea318a..0000000 --- a/Sem. 3/Tasks and Solutions/09. SumFromKtoN.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n, k; - cin >> k >> n; - - int sum = 0; - for (int i = k; i <= n; i++) - sum += i; - - cout << sum << endl; - - //or use the formula - - cout << (n*(n + 1)) / 2 - ((k - 1)*k) / 2 << endl; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/10. Pyramid.cpp b/Sem. 3/Tasks and Solutions/10. Pyramid.cpp deleted file mode 100644 index 5d9e2a9..0000000 --- a/Sem. 3/Tasks and Solutions/10. Pyramid.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= i; j++) - cout << "$"; - cout << endl; - } -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/11. Clock.cpp b/Sem. 3/Tasks and Solutions/11. Clock.cpp deleted file mode 100644 index 6386ca0..0000000 --- a/Sem. 3/Tasks and Solutions/11. Clock.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; - -int main() -{ - for (int hour = 0; hour <= 23; hour++) - { - for (int min = 0; min <= 59; min++) - { - if (hour < 10) - cout << 0; - cout << hour << ":"; - if (min < 10) - cout << 0; - cout << min << endl; - } - } -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/12. ClockWithStart.cpp b/Sem. 3/Tasks and Solutions/12. ClockWithStart.cpp deleted file mode 100644 index 1b996e1..0000000 --- a/Sem. 3/Tasks and Solutions/12. ClockWithStart.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -using namespace std; - -int main() -{ - int h, m; - cin >> h >> m; - - for (int min = m + 1; min <= 59; min++) - { - if (h < 10) - cout << 0; - cout << h << ":"; - if (min < 10) - cout << 0; - cout << min << endl; - } - - for (int hour = h+1; hour <= 23; hour++) - { - for (int min = 0; min <= 59; min++) - { - if (hour < 10) - cout << 0; - cout << hour << ":"; - if (min < 10) - cout << 0; - cout << min << endl; - } - } -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/13. ClockWithStartAndEnd.cpp b/Sem. 3/Tasks and Solutions/13. ClockWithStartAndEnd.cpp deleted file mode 100644 index af39745..0000000 --- a/Sem. 3/Tasks and Solutions/13. ClockWithStartAndEnd.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -using namespace std; - -int main() -{ - int hStart, mStart, hEnd, mEnd; - cin >> hStart >> mStart >> hEnd >> mEnd; - - for (int min = mStart + 1; min <= 59; min++) - { - if (hStart < 10) - cout << 0; - cout << hStart << ":"; - if (min < 10) - cout << 0; - cout << min << endl; - } - - for (int hour = hStart+1; hour <= hEnd-1; hour++) - { - for (int min = 0; min <= 59; min++) - { - if (hour < 10) - cout << 0; - cout << hour << ":"; - if (min < 10) - cout << 0; - cout << min << endl; - } - } - - for (int min = 0; min < mEnd; min++) - { - if (hEnd < 10) - cout << 0; - cout << hEnd << ":"; - if (min < 10) - cout << 0; - cout << min << endl; - } -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/14. Frame.cpp b/Sem. 3/Tasks and Solutions/14. Frame.cpp deleted file mode 100644 index 92de3ca..0000000 --- a/Sem. 3/Tasks and Solutions/14. Frame.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - - //Ãîðíà ðàìêà - cout << '+'; - for (int i = 0; i < n - 2; i++) - cout << '-'; - cout << '+' << endl; - - - //Ñðåäà - for (int j = 0; j < n - 2; j++) - { - cout << '|'; - for (int i = 0; i < n - 2; i++) - cout << '-'; - cout << '|' << endl; - } - - //Äîëíà ðàìêà - cout << '+'; - for (int i = 0; i < n - 2; i++) - cout << '-'; - cout << '+' << endl; -} \ No newline at end of file diff --git a/Sem. 3/Tasks and Solutions/tasks.pdf b/Sem. 3/Tasks and Solutions/tasks.pdf deleted file mode 100644 index 6c2ad50..0000000 Binary files a/Sem. 3/Tasks and Solutions/tasks.pdf and /dev/null differ diff --git a/Sem. 4/README.md b/Sem. 4/README.md deleted file mode 100644 index 5357d01..0000000 --- a/Sem. 4/README.md +++ /dev/null @@ -1,129 +0,0 @@ -**Десетична бройна система.** - -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 , 12 - -Защото използваме 10 символа: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 - -Най-малката бройна система: **Единична бройна система (Unary)** - -Символи: 1 - -1 = 1 - -2 = 11 - -3 = 111 - -4 = 1111 - -5 = 11111 - -6 = 111111 - - -**Двоична бройна система (binary)** - -Символи: 0,1 - -0 - 00000 - -1 - 00001 - -2 - 00010 - -3 - 00011 - -4 - 00100 - -5 - 00101 - -6 - 00110 - -**Троична бройна система** - -Символи: 0, 1, 2 - -0 - 00 - -1 - 01 - -2 - 02 - -3 - 10 - -4 - 11 - -5 - 12 - -6 - 20 - - -Пребобрзвуане между бройни системи. - -**1. Десетична бройна система -> k-ична(k = 2(двоична), k = 3(троична), k = 10(десетична)) бройна система.** - -**Пример 1**: Преобразуване на числото 36 от десетична бройна система в двоична бройна система. - -Т.е k = 2. - -| | | %k | -|----|--------|----| -| | n = 36 | 0 | -| /k | 18 | 0 | -| /k | 9 | 1 | -| /k | 4 | 0 | -| /k | 2 | 0 | -| /k | 1 | 1 | -| /k | 0 | | - - -**Гледаме от долу нагоре - 100100** - -**Пример 2**: Преобразуване на числото 38 от десетична бройна система в троична бройна система. - -Т.е k = 3. - -| | | %k | -|----|--------|----| -| | n = 38 | 2 | -| /k | 12 | 0 | -| /k | 4 | 1 | -| /k | 1 | 1 | -| /k | 0 | | - -**Гледаме от долу нагоре - 1102** - -**1. k-ична бройна система -> десетична бройна система.** - -**Пример 3**: Преобразуване на числото 100100 от двоична бройна система в десетична бройна система. - -0*2^0 + 0*2^1 + 1*2^2 + 0*2^3 + 0*2^4 + 1*2^5 = 4 + 32 = 36 - -**Пример 4**: Преобразуване на числото 1102 от троична бройна система в десетична бройна система - -2*3^0 + 0*3^1 + 1*3^2 + 1*3^3 = 2 + 9 + 27 = 38. - - -Всяка една променлива има **фиксиран** размер - памет, която заема. - -int - 32 бита. бит - 0 или 1 - -sizeof(int) - > 4 размер в байтове. Байт = 8 бита. - -Първият бит в int-а определя знака. - -Минимална стойност на променлива от тип int: -2^31. - -Максимална стоиност на променлива от тип int: 2^31 - 1 - -Побитови операции: Виж **bitwise_examples.cpp** - -Побитови операции(задачи): - -**Задача 1**: Да се провери дали дадено число е четно или нечетно. - -**Задача 2**: Въвежда се числa n и k и да се определи стойността на k-тия бит.(Вход: 10, 2 (000..001010) Изход: 0) - -**Задача 3**: Въвежда се число n. Да се пресметне 2^n. - -**Задача 4**: Въвежда се число n. Да се пресметне числото закодирано в предпоследните 3 бита. diff --git a/Sem. 4/Task1.cpp b/Sem. 4/Task1.cpp deleted file mode 100644 index 2fece1e..0000000 --- a/Sem. 4/Task1.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - - if (n & 1 == 1) - cout << "Odd"; - else - cout << "Even"; - -} \ No newline at end of file diff --git a/Sem. 4/Task2.cpp b/Sem. 4/Task2.cpp deleted file mode 100644 index fca8f47..0000000 --- a/Sem. 4/Task2.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n, k; - cin >> n >> k; - - int temp = 1; - temp = temp << k; - - if ((n & temp) == 0) - cout << "0"; - else - cout << "1"; - -} \ No newline at end of file diff --git a/Sem. 4/Task3.cpp b/Sem. 4/Task3.cpp deleted file mode 100644 index 1f21ba4..0000000 --- a/Sem. 4/Task3.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - - cout << (1 << n); -} \ No newline at end of file diff --git a/Sem. 4/Task4.cpp b/Sem. 4/Task4.cpp deleted file mode 100644 index 9bb0e6e..0000000 --- a/Sem. 4/Task4.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - // 14 = 000...001110 - òàêà ñ "ïîáèòîâî è" ùå âçåìåì ñàìî òåçè 3 áèòà, à îñòàíàëèòå ùå áúäàò 0. Ïîñëå ãè ïðåìåñòâàìå äî íà÷àëîòî (èçïîëçâàéêè >>). - cout << ((n & 14) >> 1); -} \ No newline at end of file diff --git a/Sem. 4/bitwise_examples.cpp b/Sem. 4/bitwise_examples.cpp deleted file mode 100644 index b6c01c0..0000000 --- a/Sem. 4/bitwise_examples.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -using namespace std; - -int main() -{ - int a = 13; // 000...01101 - int b = 20; // 000...10100 - - int r1 = a & b; // 000...00100(4) - int r2 = a | b; // 000...11101(29) - int r3 = a ^ b; // 000...11001(25) - int r4 = a >> 1;// 000...00110(6) - int r5 = b << 1;// 000..101000(40) - - std::cout << r1 << endl; - std::cout << r2 << endl; - std::cout << r3 << endl; - std::cout << r4 << endl; - std::cout << r5 << endl; -} diff --git a/Sem. 5/README.md b/Sem. 5/README.md deleted file mode 100644 index b65599b..0000000 --- a/Sem. 5/README.md +++ /dev/null @@ -1,18 +0,0 @@ -**Задача 1:** Въвежда се неотрицателно число n. Да се провери дали n е просто. - -**Задача 2:** Въвежда се неотрицателно число n. Да се отпечата неговото разбиване на прости множители. - -*Вход: 288, Изход: 2^5 * 3^2* - -**Задача 3:** Въвежда се неотрицателно число n. Пресметнете n + 1, използвайки само цикли и побитови операции. - -**Задача 4:** Въвеждат се неотрицателни числа n и k. Пресметнете n + k, използвайки само цикли и побитови операции. - -**Задача 5:** Въвеждат се неотрицателни числа n и k. Пресметнете n * k, използвайки само цикли и побитови операции. - -**Задача 6:** Всяко естествено число се представя по единствен начин като сума на **различни**(не се повтарят) степени на двойката. -Въвежда се естествено число n. Отпечатайте това разбиване на n. - -*Вход: 26, Изход: 2^1 + 2^3 + 2^4* - -*Вход: 15, Изход: 2^0 + 2^1 + 2^2 + 2^3* diff --git a/Sem. 5/Task 1.cpp b/Sem. 5/Task 1.cpp deleted file mode 100644 index 20ca708..0000000 --- a/Sem. 5/Task 1.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -using namespace std; - -int main() -{ - unsigned int n; - cin >> n; - - //Ðåøåíèå 1: - bool isPrime1 = true; - for (int i = 2; i <= n - 1; i++) - { - if (n % i == 0) - isPrime1 = false; - } - cout << isPrime1 << endl; - // Ðåøåíèåòî ðàáîòè. Íî ïðàâè èçëèøíè ïðîâåðêè. Íå å íåîáõîäèìî äà òúðñèì äåëèòåë ÷àê äî n-1. - // Àêî íå íàìåðèì äåëèòåë îò êîðåí(n), òî íÿìà äà íàìåðèì è ñëåä êîðåíà. - - //Ðåøåíèå 2: - bool isPrime2 = true; - for (int i = 2; i <= sqrt(n); i++) - { - if (n % i == 0) - isPrime2 = false; - } - cout << isPrime2 << endl; - - // Ðåøåíèåòî ïàê ðàáîòè. Íî íà âñÿêà ïðîâåðêà i <= sqrt(n) ïðåñìÿòàìå êîðåí(n), êîåòî å î÷åâèäíî, ÷å å èçëèøíî. - // Ìîæå äà ãî ñìåòíåì âåäíúæ è ïîñëå äà ãî ïîëçâàìå. - - //Ðåøåíèå 3: - bool isPrime3 = true; - double temp = sqrt(n); - for (int i = 2; i <= temp; i++) - { - if (n % i == 0) - isPrime3 = false; - } - cout << isPrime3 << endl; - - // È òîâà ðåøåíèå äàâà âåðåí ðåçóëòàò. Íî îòíîâî å âúçìîæíî äà ïðàâè èçëèøíè ïðîâåðêè. - // Ïðè âúâåæäàíå íà ÷èñëîòî 2000000, î÷åâèäíî áè áèëî, ÷å ÷èñëîòî ÍÅ å ïðîñòî, ïîíåæå ñå äåëè íà 2. - // Íî íàøåòî ðåøåíèå ùå ïðîäúëæè äà òúðñè äåëèòåëè, äîðè ñëåä êàòî å âèäÿëî, ÷å èìà òàêúâ (â ñëó÷àÿ ÷èñëîòî 2). - - //Ôèíàëíî ðåøåíèå: - bool isPrime4 = true; - double temp2 = sqrt(n); - for (int i = 2; i <= temp2; i++) - { - if (n % i == 0) - { - isPrime4 = false; - break; - } - } - cout << isPrime4 << endl; -} \ No newline at end of file diff --git a/Sem. 5/Task 2.cpp b/Sem. 5/Task 2.cpp deleted file mode 100644 index 0f4408d..0000000 --- a/Sem. 5/Task 2.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -using namespace std; - -int main() -{ - unsigned int n; - cin >> n; - - for (int i = 2; n != 1; i++) //Âñè÷êè âúçìîæíè äåëèòåëè (ìíîæèòåëè) íà n 2,3,4,5,..., - { - // Ïðîâåðÿâàìå äàëè ÷èñëîòî å ïðîñòî (ïîíåæå íè èíòåðåñóâàò ñàìî ïðîñòè ìíîæèòåëè) - bool isPrime = true; - double temp = sqrt(i); - for (int j = 2; j <= temp; j++) - { - if (i % j == 0) - { - isPrime = false; - break; - } - } - - if (!isPrime) - continue; //Àêî íå å ïðîñòî - íå íè èíòåðåñóâà òîâà ÷èñëî. Ïðåìèíàâàìå êúì ñëåäâàùîòî. - - // Ùîì ñìå ñòèãíàëè òóê, ñìå óáåäåíè, ÷å i å ïðîñòî ÷èñëî. - // Èñêàìå äà âèäèì êîëêî ïúòè i äåëè n. - - int pow = 0; - while (n % i == 0) - { - n /= i; - pow++; - } - - if (pow != 0) //Àêî ïîíå âåäíúæ ãî å ðàçäåëèëî - çíà÷è ó÷àñòâà â ðàçáèâàíåòî íà ïðîñòè ìíîæèòåëè. - cout << i << "^" << pow << " "; - } -} \ No newline at end of file diff --git a/Sem. 5/Task 3.cpp b/Sem. 5/Task 3.cpp deleted file mode 100644 index 6723ee2..0000000 --- a/Sem. 5/Task 3.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -using namespace std; - - -//Àëãîðèòúìúò çà ñúáèðàíå ñ 1 â äâîè÷åí çàïèñ: -//Îò äÿñíî íà ëÿâî - ïðàâèì âñè÷êè 1-öè íà 0, äîêàòî íå ñðåùíåì ïúðâàòà 0. -//Ïúðâàòà 0 ÿ ïðàâèì íà 1. - -// 101001111 + 1 -// 101010000 -int main() -{ - unsigned int n; - cin >> n; - - int mask = 1; //Íàé-äåñíèÿò áèò íà ìàñêàòà å 1-öà. Âñè÷êè äðóãè ñà 0-ëè. - - - while ((n & mask) > 0) //Ïðîâåðÿâàìå äàëè òåêóùèÿ áèò å 1-öà. (ïðè ïúðâîòî âëèçàíå, ïðîâåðÿâàìå íàé-äåñíèÿ) - { - n ^= mask; // Ïðàâèì ãî íà 0 ( n = n ^ mask) - mask <<= 1; // Îòìåñòâàìå ìàñêàòà, çà äà ïðîâåðèì áèò-à â ëÿâî. (mask = mask << 1) - } - - //Îòêðèëè ñìå ïúðâàòà 0. 1-öàòà å íà òî÷íàòà ïîçèöèÿ â ìàñêàòà. - n |= mask; // Ïðàâèì íà 1-öa (n = n | mask) -} \ No newline at end of file diff --git a/Sem. 5/Task 4.cpp b/Sem. 5/Task 4.cpp deleted file mode 100644 index 6d57f92..0000000 --- a/Sem. 5/Task 4.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -using namespace std; - -int main() -{ - unsigned int n, k; - cin >> n >> k; - - - //Изпълняваме k пъти събирането на n с 1 - for (int i = 0; i < k; i++) - { - //Събираме n с 1-ца (кодът от миналата задача) - int mask = 1; - while ((n & mask) > 0) - { - n ^= mask; - mask <<= 1; - } - n |= mask; - } - cout << n << endl; -} diff --git a/Sem. 5/Task 5.cpp b/Sem. 5/Task 5.cpp deleted file mode 100644 index 6f3d0dd..0000000 --- a/Sem. 5/Task 5.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -using namespace std; - -int main() -{ - unsigned int n, k; - cin >> n >> k; - - //Ñìÿòàìå n*k. n+n+n...+n (k ïúòè). - //Ïðèëàãàìå êîäà îò ïðåäèøíàòà çàäà÷à k ïúòè - - - int result = 0; - - //Събирането с n го правим k пъти. Т.е става точно n*k - for (int t = 0; t < k; t++) - { - - //Събирането с 1 го правим пъти. Т.е става +n - for (int i = 0; i < n; i++) - { - //Събираме n с 1. - int mask = 1; - while ((result & mask) > 0) - { - result ^= mask; - mask <<= 1; - } - result |= mask; - } - } - cout << result << endl; -} diff --git a/Sem. 5/Task 6.cpp b/Sem. 5/Task 6.cpp deleted file mode 100644 index 415cae4..0000000 --- a/Sem. 5/Task 6.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -using namespace std; - -int main() -{ - unsigned int n; - cin >> n; - - int currentPosition = 0; - while (n != 0) - { - if (n % 2 == 1) //Проверяваме последния бит дали е 1. - { - cout << "2^" << currentPosition << " "; - } - currentPosition++; - n >>= 1; // Премахваме последния бит и предпоследния става последен (n /=2); - } -} diff --git a/Sem. 6/README.md b/Sem. 6/README.md deleted file mode 100644 index e8c4d0b..0000000 --- a/Sem. 6/README.md +++ /dev/null @@ -1,35 +0,0 @@ -**Задача 1:** Въвежда се неотрицателно число n. Да се отпечатат всички двойки прости числа, които са във вида 6k-1 и 6k+1. - -**Задача 2:** Напишете функция, която приема неотрицателно число n и връща числото обърнато - -*Вход: 288, Изход: 822* - -**Задача 3:** Напишете функция, която приема неотрицателно число и връща дали числото е палиндром. - -**Задача 4:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е суфикс на n. - -*Вход: 288, 88, Изход: true* - -**Задача 5:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е префикс на n. - -*Вход: 288, 28, Изход: true* - -**Задача 6:** Напишете функция, която приема неотрицателни числа n и k и връща дали k се съдържа в n. - -*Вход: 2831, 83, Изход: true* - -**Задача 7:** Напишете функция, която приема неотрицателно число n и проверява дали има 4 последователни еднакви цифри. - -*Вход: 28777731, 83, Изход: true* - -**Задача 8:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани във възходящ ред. - -*Вход: 122239, Изход: true* - -**Задача 9:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани в низходящ ред. - -*Вход: 99943, Изход: true* - -**Задача 10:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са еднакви. - -*Вход: 111111, Изход: true* diff --git a/Sem. 6/Task_1(with functions).cpp b/Sem. 6/Task_1(with functions).cpp deleted file mode 100644 index db68d0d..0000000 --- a/Sem. 6/Task_1(with functions).cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; - -bool isPrime(int number) -{ - double temp = sqrt(number); - for (int i = 2; i <= temp; i++) - { - if (number % i == 0) - return false; //Ñïèðà ôóíêöèÿòà è âðúùà îòãîâîð - ëúæà - } - return true; -} - -int main() -{ - int n; - cin >> n; - - for (int i = 6; i <= n; i += 6) - { - if (isPrime(i - 1) && isPrime(i + 1)) - cout << i - 1 << " " << i + 1 << endl; - } - -} \ No newline at end of file diff --git a/Sem. 6/Task_1(without functions).cpp b/Sem. 6/Task_1(without functions).cpp deleted file mode 100644 index 9e5bcdb..0000000 --- a/Sem. 6/Task_1(without functions).cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -using namespace std; - -int main() -{ - int n; - cin >> n; - - for (int i = 6; i <= n; i+=6) - { - int firstNumToCheck = i - 1, secondNumToCheck = i + 1; - - double temp = sqrt(firstNumToCheck); - bool isFirstNumPrime = true; - for (int j = 2; j <= temp; j++) - { - if (firstNumToCheck % j == 0) - { - isFirstNumPrime = false; - break; - } - } - - if (!isFirstNumPrime) - continue; - double temp2 = sqrt(secondNumToCheck); - bool isSecondNumPrime = true; - for (int j = 2; j <= temp2; j++) - { - if (secondNumToCheck % j == 0) - { - isSecondNumPrime = false; - break; - } - } - if (isSecondNumPrime) - cout << firstNumToCheck << " " << secondNumToCheck << endl; - } - -} \ No newline at end of file diff --git a/Sem. 6/Tasks_2,3,4,5,6,7,8,9,10.cpp b/Sem. 6/Tasks_2,3,4,5,6,7,8,9,10.cpp deleted file mode 100644 index 1d9666d..0000000 --- a/Sem. 6/Tasks_2,3,4,5,6,7,8,9,10.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include -using namespace std; - - -//Task 2 -unsigned int reverse(unsigned int number) -{ - int result = 0; - - while (number != 0) - { - int lastDigit = number % 10; - (result *= 10) += lastDigit; - number /= 10; - } - - return result; -} - -//Task 3 -bool isPalindrome(unsigned int n) -{ - return n == reverse(n); -} - -//Task 4 -bool isSuffix(unsigned int n, unsigned int k) -{ - if (n < k) - return false; - while (k != 0) - { - int lastDigitFromN = n % 10; - int lastDigitFromK = k % 10; - if (lastDigitFromN != lastDigitFromK) - return false; - n /= 10; - k /= 10; - } - return true; -} - -// Task 5 -bool isPrefix(unsigned int n, unsigned int k) -{ - return isSuffix(reverse(n), reverse(k)); -} - -// Task 6 -bool isInfix(unsigned int n, unsigned int k) -{ - if (k > n) - return false; - while (n >= k) - { - if (isSuffix(n, k)) - return true; - n /= 10; - } - return false; -} - -// Task 7 -bool hasConsecutiveFourDigits(unsigned int n) -{ - for (int i = 1111; i <= 9999; i+=1111) - { - if (isInfix(n, i)) - return true; - } - for (int i = 10000; i <= 90000; i += 10000) - { - if (isInfix(n, i)) - return true; - } - return false; -} - -// Task 8 -bool areDigitsSortedIncreasing(unsigned int n) -{ - while (n >= 10) - { - int lastDigit = n % 10; - int lastLastDigit = (n / 10) % 10; - - if (lastLastDigit > lastDigit) - return false; - n /= 10; // - } - return true; -} - -// Task 9 -bool areDigitsSortedDecreasing(unsigned int n) -{ - return areDigitsSortedIncreasing(reverse(n)); -} - -// Task 10 -bool areAllDigitsTheSame(unsigned int n) -{ - return areDigitsSortedIncreasing(n) && areDigitsSortedDecreasing(n); -} -int main() -{ - cout << areAllDigitsTheSame(777); -} diff --git a/Sem. 7/BullsAndColls.cpp b/Sem. 7/BullsAndColls.cpp deleted file mode 100644 index 5b5a54e..0000000 --- a/Sem. 7/BullsAndColls.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -using namespace std; - - -//Èãðàòà áèêîâå è êðàâè. -// Êîìï. ãåíåðèðà ñëó÷àéíî ÷èñëî âè èíòåðâàëà [1000...9999]. -// Íèå òðÿáâà äà ãî ïîçíàåì. - - -// 4278 - 1 áèê, 1 êðàâà (áèê - ÷èñëî è ïîçèöèÿòà), (êðàâà - ÷èñëîòî , íî è ïîçèöèÿòà) -// Ïîçíàâàì ÷èñëîòî, êîãàòî èìàì 4 áèêà - -bool hasDuplicateDigits(int n) ///1343 -{ - const int DIGITCOUNT = 10; - bool found[DIGITCOUNT]; - for (int i = 0; i < DIGITCOUNT; i++) - found[i] = false; - while (n != 0) - { - int lastDigit = n % 10; - if (found[lastDigit] == true) - return true; - else - found[lastDigit] = true; - n /= 10; - } - return false; -} - -void convertNumberToArr(int n, int arr[]) -{ - - for (int i = 3; i >= 0; i--) - { - arr[i] = n % 10; - n /= 10; - } - -} -int countBulls(int myNumber[], int compNumber[]) -{ - int bullsCount = 0; - for (int i = 0; i <= 3; i++) - { - if (myNumber[i] == compNumber[i]) - bullsCount++; - } - return bullsCount; -} -int countCows(int myNumber[], int compNumber[]) -{ - int cowsCount = 0; - - for (int i = 0; i <= 3; i++) - { - int myDigit = myNumber[i]; - for (int j = 0; j <= 3; j++) - { - if (j == i) // çà äà íå áðîèì áèêîâåòå - continue; - if (myDigit == compNumber[j]) - cowsCount++; - } - } - return cowsCount; -} -int main() -{ - int numberToGuess; - do - { - numberToGuess = 1000 + rand() % 9000; // [1000..9999] - } - while (hasDuplicateDigits(numberToGuess)); - - cout << "Computer has picked a number! Try to guess it!" <> myNumber; - int myNumberArr[4]; - convertNumberToArr(myNumber, myNumberArr); - - bullsCount = countBulls(myNumberArr, numberToGuessArr); - cowsCount = countCows(myNumberArr, numberToGuessArr); - - cout << "Bulls: " << bullsCount << " Cows:" << cowsCount << endl; - - - } while (bullsCount != 4); - - cout << "Success!" << endl; -} \ No newline at end of file diff --git a/Sem. 7/README.md b/Sem. 7/README.md deleted file mode 100644 index 2c6303a..0000000 --- a/Sem. 7/README.md +++ /dev/null @@ -1,9 +0,0 @@ -### Код от семинарите по "Увод в програмирането" - спец. Компютърни науки, група 7 - зимен семестър 2020/2021 - - - - **Тема 1 (09.10.2020) :** Променливи. Типове променливи. Оператори. Преобразуване между типове. - - **Тема 2 (16.10.2020) :** Приоритет на операторите. Асоциативност. Условни провеки (if, switch) - - **Тема 3 (23.10.2020 и 28.10.2020) :** Жизнен цикъл на променливите. Оператори за цикъл(while, for). Оператор break. Задачи. - - **Тема 4 (04.11.2020) :** Бройни системи. Побитови операции. - - **Тема 5 (13.11.2020) :** Задачи за цикли и побитови операции. - - **Тема 6 (17.11.2020) :** Функции. \ No newline at end of file -- cgit v1.3.1-23-gd82d