diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/A - Gravity Flip.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/A - Gravity Flip.cpp new file mode 100644 index 0000000..ae8944c --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/A - Gravity Flip.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + } + sort(arr, arr + n); + for (int i = 0; i < n; ++i) { + cout << arr[i] << ' '; + } + cout << endl; +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/B - Currency System in Geraldion.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/B - Currency System in Geraldion.cpp new file mode 100644 index 0000000..c98f346 --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/B - Currency System in Geraldion.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + } + int mn = *min_element(arr, arr + n); + if (mn == 1) + cout << "-1\n"; + else + cout << 1 << endl; +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/C - Translation.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/C - Translation.cpp new file mode 100644 index 0000000..397790d --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/C - Translation.cpp @@ -0,0 +1,14 @@ +#include + +using namespace std; + +int main() { + string s, t; + cin >> s >> t; + reverse(s.begin(), s.end()); + if (s == t) + cout << "YES\n"; + else + cout << "NO\n"; +} +// \ No newline at end of file diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/D - Songs Compression.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/D - Songs Compression.cpp new file mode 100644 index 0000000..0abe3dc --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/D - Songs Compression.cpp @@ -0,0 +1,30 @@ +#include + +using namespace std; + +int main() { + int numOfSongs, spaceOfFlashDrive; + cin >> numOfSongs >> spaceOfFlashDrive; + int beforeComp[numOfSongs], afterComp[numOfSongs]; + long long spaceOfMusic = 0; + for (int i = 0; i < numOfSongs; ++i) { + cin >> beforeComp[i] >> afterComp[i]; + spaceOfMusic += beforeComp[i]; + } + int gainSpace[numOfSongs]; + for (int i = 0; i < numOfSongs; ++i) { + gainSpace[i] = beforeComp[i] - afterComp[i]; + } + sort(gainSpace, gainSpace + numOfSongs, greater<>()); + int ans = 0; + for (int i = 0; i < numOfSongs and spaceOfMusic > spaceOfFlashDrive; ++i) { + spaceOfMusic -= gainSpace[i]; + ans++; + } + if (spaceOfMusic > spaceOfFlashDrive) + cout << -1 << endl; + else + cout << ans << endl; + + +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/E - Chores.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/E - Chores.cpp new file mode 100644 index 0000000..6b3eede --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/E - Chores.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main() { + int n, k, x; + cin >> n >> k >> x; + int arr[n]; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + } + for (int i = n - 1; i >= 0 and k > 0; --i) { + arr[i] = x; + k--; + } + int sum = 0; + for (int i = 0; i < n; ++i) { + sum += arr[i]; + } + cout << sum << endl; + +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/F - I_love-username.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/F - I_love-username.cpp new file mode 100644 index 0000000..21a488d --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/F - I_love-username.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + } + int mn = arr[0], mx = arr[0]; + int ans = 0; + for (int i = 1; i < n; ++i) { + if (arr[i] > mx) { + ans++; + mx = arr[i]; + } + if (arr[i] < mn) { + ans++; + mn = arr[i]; + } + } + cout << ans << endl; +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/G - Puzzles.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/G - Puzzles.cpp new file mode 100644 index 0000000..461921f --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/G - Puzzles.cpp @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int main() { + int n, m; + cin >> n >> m; + int arr[m]; + for (int i = 0; i < m; ++i) { + cin >> arr[i]; + } + sort(arr, arr + m); + n--; + int mn = 1000000000; + for (int i = n; i < m; ++i) { + if (arr[i] - arr[i - n] < mn) { + mn = arr[i] - arr[i - n]; + } + } + cout << mn << endl; +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/H - Is your horseshoe on the other hoof.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/H - Is your horseshoe on the other hoof.cpp new file mode 100644 index 0000000..81f59ec --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/H - Is your horseshoe on the other hoof.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() { + int arr[4]; + for (int i = 0; i < 4; ++i) { + cin >> arr[i]; + } + sort(arr, arr + 4); + int ans = 0; + for (int i = 1; i < 4; ++i) { + if (arr[i] == arr[i - 1]) + ans++; + } + cout << ans << endl; +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/I - Tram.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/I - Tram.cpp new file mode 100644 index 0000000..dd3f1ce --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/I - Tram.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +int main() { + int n; + cin >> n; + int people = 0, mx = 0; + for (int i = 0; i < n; ++i) { + int a, b; + cin >> a >> b; + people -= a; + people += b; + if (people > mx) + mx = people; + } + cout << mx << endl; + + +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/J - Count Order.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/J - Count Order.cpp new file mode 100644 index 0000000..493447d --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/J - Count Order.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int main() { + int n; + cin >> n; + int p[n], q[n], permutation[n]; + for (int i = 0; i < n; ++i) { + cin >> p[i]; + } + for (int i = 0; i < n; ++i) { + cin >> q[i]; + } + for (int i = 1; i <= n; ++i) { + permutation[i - 1] = i; + } + int a = 0, b = 0; + int cnt = 0; + do { + bool isEqual = true; + for (int i = 0; i < n; ++i) { + if (p[i] != permutation[i]) + isEqual = false; + } + cnt++; + if (isEqual) { + a = cnt; + break; + } + } while (next_permutation(permutation, permutation + n)); + + for (int i = 1; i <= n; ++i) { + permutation[i - 1] = i; + } + + cnt = 0; + do { + bool isEqual = true; + for (int i = 0; i < n; ++i) { + if (q[i] != permutation[i]) + isEqual = false; + } + cnt++; + if (isEqual) { + b = cnt; + break; + } + } while (next_permutation(permutation, permutation + n)); + cout << abs(a - b) << endl; + +} diff --git a/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/K - Arrival of the General.cpp b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/K - Arrival of the General.cpp new file mode 100644 index 0000000..a00b57b --- /dev/null +++ b/Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/K - Arrival of the General.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + } + int mx = arr[0], mxPos = 0; + for (int i = 0; i < n; ++i) { + if (mx < arr[i]) { + mx = arr[i]; + mxPos = i; + } + } + int ans = 0; + while (mxPos > 0) { + swap(arr[mxPos], arr[mxPos - 1]); + ans++; + mxPos--; + } + int mn = arr[n - 1], mnPos = n - 1; + for (int i = n - 1; i >= 0; --i) { + if (mn > arr[i]) { + mn = arr[i]; + mnPos = i; + } + } + while (mnPos < n - 1) { + swap(arr[mnPos], arr[mnPos + 1]); + ans++; + mnPos++; + } + cout << ans << endl; + +}