Skip to content

Commit

Permalink
Merge pull request #57 from Coach-Academy/Rania154-patch-2
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
7oSkaaa authored Dec 13, 2023
2 parents 0c1a94e + ab62aa9 commit 6d34eb9
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<bits/stdc++.h>

#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 << " " <<c2 << endl;
}

return 0;
}
33 changes: 33 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<bits/stdc++.h>

#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;
}
54 changes: 54 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<bits/stdc++.h>

#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;
}
46 changes: 46 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<bits/stdc++.h>

#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;
}
31 changes: 31 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<bits/stdc++.h>

#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;
}
37 changes: 37 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<bits/stdc++.h>

#define ll long long
#define endl '\n'
using namespace std;

void doWork()
{
int n;
cin >> n;
vector<int> 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;
}
47 changes: 47 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/G.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<bits/stdc++.h>

#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;
}
48 changes: 48 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/H.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<bits/stdc++.h>

#define ll long long
#define endl '\n'
using namespace std;

void doWork()
{
int n;
while (true)
{
cin >> n;
if ( n == 0)
break;
deque<int> 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;
}
47 changes: 47 additions & 0 deletions Level 2 Class 1/Practice G1/Week 10/I.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<bits/stdc++.h>

#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;
}
Loading

0 comments on commit 6d34eb9

Please sign in to comment.