-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Coach-Academy/MohamedAmir-Patch-1
c103 practice G3 week 5
- Loading branch information
Showing
11 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/A - Gravity Flip.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
} |
17 changes: 17 additions & 0 deletions
17
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/B - Currency System in Geraldion.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
} |
14 changes: 14 additions & 0 deletions
14
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/C - Translation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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"; | ||
} | ||
// |
30 changes: 30 additions & 0 deletions
30
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/D - Songs Compression.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
|
||
|
||
} |
22 changes: 22 additions & 0 deletions
22
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/E - Chores.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/F - I_love-username.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
} |
21 changes: 21 additions & 0 deletions
21
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/G - Puzzles.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
} |
17 changes: 17 additions & 0 deletions
17
...PU - Standard - L1 - C103/Practice G3/Week 05/H - Is your horseshoe on the other hoof.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
} |
20 changes: 20 additions & 0 deletions
20
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/I - Tram.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
|
||
|
||
} |
52 changes: 52 additions & 0 deletions
52
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/J - Count Order.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
Level 1/CPU - Standard - L1 - C103/Practice G3/Week 05/K - Arrival of the General.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <bits/stdc++.h> | ||
|
||
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; | ||
|
||
} |