From ab62aa9a81647b760b16d721fa2007ccfd58cef5 Mon Sep 17 00:00:00 2001 From: Rania Heragy <76109504+Rania154@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:06:45 +0200 Subject: [PATCH] Add files via upload --- Level 2 Class 1/Practice G1/Week 10/A.cpp | 23 ++++++++++ Level 2 Class 1/Practice G1/Week 10/B.cpp | 33 ++++++++++++++ Level 2 Class 1/Practice G1/Week 10/C.cpp | 54 +++++++++++++++++++++++ Level 2 Class 1/Practice G1/Week 10/D.cpp | 46 +++++++++++++++++++ Level 2 Class 1/Practice G1/Week 10/E.cpp | 31 +++++++++++++ Level 2 Class 1/Practice G1/Week 10/F.cpp | 37 ++++++++++++++++ Level 2 Class 1/Practice G1/Week 10/G.cpp | 47 ++++++++++++++++++++ Level 2 Class 1/Practice G1/Week 10/H.cpp | 48 ++++++++++++++++++++ Level 2 Class 1/Practice G1/Week 10/I.cpp | 47 ++++++++++++++++++++ Level 2 Class 1/Practice G1/Week 10/J.cpp | 44 ++++++++++++++++++ 10 files changed, 410 insertions(+) create mode 100644 Level 2 Class 1/Practice G1/Week 10/A.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/B.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/C.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/D.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/E.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/F.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/G.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/H.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/I.cpp create mode 100644 Level 2 Class 1/Practice G1/Week 10/J.cpp diff --git a/Level 2 Class 1/Practice G1/Week 10/A.cpp b/Level 2 Class 1/Practice G1/Week 10/A.cpp new file mode 100644 index 0000000..958437f --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/A.cpp @@ -0,0 +1,23 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t; + cin >> t; + while (t--) + { + int n; + cin >> n; + int c1 = (n/3) + (n%3 == 1); + int c2 = (n/3) + (n%3 == 2); + cout << c1 << " " < + +#define ll long long +#define endl '\n' +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t; + cin >> t; + while (t--) + { + int n; + cin >> n; + int o =0, e =0; + for (int i = 0; i < 2*n; ++i) { + int x ; + cin >> x; + if ( x%2) + o++; + else + e++; + } + if ( e == o) + cout << "Yes\n"; + else + cout << "No\n"; + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/C.cpp b/Level 2 Class 1/Practice G1/Week 10/C.cpp new file mode 100644 index 0000000..53f361b --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/C.cpp @@ -0,0 +1,54 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n; + cin >> n; + int winner = 0; + int a[n][5]; + for (int i = 0; i < n; ++i) { + int cnt = 0; + for (int j = 0; j < 5; ++j) { + cin >> a[i][j]; + if ( a[winner][j] > a[i][j]) + cnt++; + } + if ( cnt >= 3 ) + { + winner = i; + } + } + for (int i = 0; i < n; ++i) { + int cnt = 0; + for (int j = 0; j < 5; ++j) { + if ( a[winner][j] > a[i][j]) + cnt++; + } + if ( cnt >= 3 ) + { + winner = -1; + break; + } + } + if ( winner == -1) + cout << -1 << endl; + else + cout << winner+1 << endl; +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t; + cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/D.cpp b/Level 2 Class 1/Practice G1/Week 10/D.cpp new file mode 100644 index 0000000..aa4fc97 --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/D.cpp @@ -0,0 +1,46 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n,a,b; + cin >> n >> a>> b; + ll x = 1; + if ( a == 1) + { + if ( (n-1)%b == 0) + cout << "Yes\n"; + else + cout << "No\n"; + } + else + { + while (x <= n) + { + int rem = n-x; + if ( rem %b ==0) + { + cout << "Yes\n"; + return; + } + x *= a; + } + cout << "No\n"; + } +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t; + cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/E.cpp b/Level 2 Class 1/Practice G1/Week 10/E.cpp new file mode 100644 index 0000000..6a2e632 --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/E.cpp @@ -0,0 +1,31 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n; + cin >> n; + ll sum =0; + for (int i = 0,x; i < n; ++i) { + cin >> x; + sum += x; + } + ll rem = sum%n; + cout << rem * ( n-rem) << endl; +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t; + cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/F.cpp b/Level 2 Class 1/Practice G1/Week 10/F.cpp new file mode 100644 index 0000000..398e93c --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/F.cpp @@ -0,0 +1,37 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; ++i) { + cin >> v[i]; + } + sort(v.begin(), v.end()); + int ans =0; + for (int i = 0; i < n; ++i) { + int l = i; + int r = std::upper_bound(v.begin(), v.end(), v[i]+5) - v.begin()-1; + int len = (r- l +1 ); + ans = max(ans , len); + } + cout << ans << endl; +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t=1; + //cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/G.cpp b/Level 2 Class 1/Practice G1/Week 10/G.cpp new file mode 100644 index 0000000..da40c94 --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/G.cpp @@ -0,0 +1,47 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n , k; + cin >> n >> k; + string a,b; + cin >> a >> b; + int fa[30]={}, fb[30]={}; + for (int i = 0; i < n; ++i) { + fa [ a[i] - 'a']++; + fb [ b[i] - 'a'] ++; + } + for (int i = 0; i < 26; ++i) { + int dif = fa[i] - fb[i]; + if ( dif < 0) + { + cout << "No\n"; + return; + } + if ( dif %k !=0) + { + cout << "No\n"; + return; + } + fa[i+1] += dif; + } + cout << "Yes\n"; + +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t=1; + cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/H.cpp b/Level 2 Class 1/Practice G1/Week 10/H.cpp new file mode 100644 index 0000000..8ba4cfd --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/H.cpp @@ -0,0 +1,48 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n; + while (true) + { + cin >> n; + if ( n == 0) + break; + deque dq; + for (int i = 1; i <= n; ++i) { + dq.push_back(i); + } + cout << "Discarded cards:"; + while (dq.size() > 1) + { + + cout << " " << dq.front(); + dq.pop_front(); + dq.push_back(dq.front()); + dq.pop_front(); + if ( dq.size() > 1) + cout << ","; + + } + cout << endl; + cout << "Remaining card: " << dq.front() << endl; + } + +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t=1; + // cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/I.cpp b/Level 2 Class 1/Practice G1/Week 10/I.cpp new file mode 100644 index 0000000..25b7e1c --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/I.cpp @@ -0,0 +1,47 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + int n; + cin >> n; + int f[25] = {}; + for (int i = 0; i < n; ++i) { + int x; + cin >> x; + for (int j = 0; j < 25; ++j) { + if (x & ( 1 << j)) + f[j]++; + } + } + ll ans =0; + for (int i = 0; i < n; ++i) { + ll x =0; + for (int j = 0; j < 25; ++j) { + if ( f[j] ) + { + f[j] -- ; + x |= ( 1 << j); + } + } + ans += x*x; + } + cout << ans << endl; + +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t=1; + // cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file diff --git a/Level 2 Class 1/Practice G1/Week 10/J.cpp b/Level 2 Class 1/Practice G1/Week 10/J.cpp new file mode 100644 index 0000000..dfad4be --- /dev/null +++ b/Level 2 Class 1/Practice G1/Week 10/J.cpp @@ -0,0 +1,44 @@ +#include + +#define ll long long +#define endl '\n' +using namespace std; + +void doWork() +{ + map< int , ll > mp; + ll ans = 0; + int n , k; + cin >> n >> k; + for (int i = 0; i < n; ++i) { + int x; + cin >> x; + if ( x%k == 0) + continue; + int rem = k - (x%k); + if ( mp[rem] == 0) + { + mp[rem] = 1+rem; + ans = max(mp[rem] , ans); + } + else + { + mp[rem] += k; + ans = max(mp[rem] , ans); + } + } + cout << ans << endl; +} +int main() { + ios::sync_with_stdio(false); + cout.tie(nullptr); + cin.tie(nullptr); + int t=1; + cin >> t; + while (t--) + { + doWork(); + } + + return 0; +} \ No newline at end of file