From fe5a64bc48dd8b440fe13883f47c8fe5938ba080 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 10 Apr 2023 09:39:52 +0300 Subject: [DAA/i198] Added current work on maycamp previous exam exercises --- .../Practicum/Maycamp-198_Beach.cpp | 21 ++++++++++++ .../Practicum/Maycamp-198_Mathematics.cpp | 34 +++++++++++++++++++ .../Practicum/Maycamp-198_Palindrome.cpp | 38 ++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Beach.cpp create mode 100644 Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp create mode 100644 Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Palindrome.cpp diff --git a/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Beach.cpp b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Beach.cpp new file mode 100644 index 0000000..7cacde5 --- /dev/null +++ b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Beach.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +using namespace std; + +int main() { + int T = 0; + scanf("%d", &T); + vector> a; + int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0; + for (int i = 0; i < T; i++) { + scanf("%d %d %d %d %d %d", &t1, &t2, &t3, &t4, &t5, &t6); + a.push_back({t1, t2, t3, t4, t5, t6}); + } + for (vector& b : a) { + l*p + r*(1-p) = 0 + (l-r)p + r = 0 + p = r/(r-l) + p = b[] + } +} diff --git a/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp new file mode 100644 index 0000000..47a846d --- /dev/null +++ b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +using namespace std; + + +int main() { + int n = 0, l = 0, r = 0; + scanf("%d %d %d", &n, &l, &r); + vector a; + short temp = 0; + for (int i = 0; i < n; i++) { + scanf("%hd", &temp); + a.push_back(temp); + } + sort(a.begin(), a.end()); + long long sum = 0; + l = n-l; + r = n-r; + for (int i = 0; i < n; i++) { + if (i == l || i == r) { + printf("%d ", a[i]); + if (l == r) + printf("%d ", a[i]); + } + else if (i > r) { + sum -= a[i]; + } + else if (i > l) { + sum += a[i]; + } + } + printf("%lld", sum); +} diff --git a/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Palindrome.cpp b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Palindrome.cpp new file mode 100644 index 0000000..2308171 --- /dev/null +++ b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Palindrome.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +using namespace std; + +int letters[200] = { 0 }; + +int main() { + char input[1000010] = { '\0' }; + scanf("%s", input); + for (int i = 0; input[i] != '\0'; i++) { + letters[(int)input[i]]++; + } + deque out; + int odd = -1; + for (int i = 0; i < 200; i++) { + if (letters[i] % 2 == 1) { + if (odd < 0) odd = i; + else { + printf("IMPOSSIBLE"); + return 0; + } + } + } + if (odd > 0) { + out.push_back((char)odd); + letters[odd]--; + } + for (int i = 199; i >= 0; i--) { + for (int j = letters[i] / 2; j < letters[i]; j++) { + out.push_front((char)i); + out.push_back((char)i); + } + } + for (char& ch : out) { + printf("%c", ch); + } +} -- cgit v1.3.1-23-gd82d