Skip to content

Commit

Permalink
Merge pull request #58 from Coach-Academy/G2-Rady
Browse files Browse the repository at this point in the history
week 09 problems
  • Loading branch information
mohamedrady45 authored Apr 28, 2024
2 parents 077bca2 + 19ac14c commit 277b786
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
void fast ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

}
int main()
{
fast();
int t;
cin >> t;
while (t--){
string s , ss;
cin >> s >> ss;
map<char , bool > mp;
for (char i : s){
mp[i] = 1;
}
bool ok = 0;
for (char i : ss){
if (mp[i]){
ok = 1;
}
}
if (ok)
cout << "YES\n";
else cout << "NO\n";
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;
void fast ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

}
int main()
{
fast();
string original = "qwertyuiopasdfghjkl;zxcvbnm,./";
map<char,int>mp;
char c ;
string s;
cin >> c >> s;
for (int i=0;i<original.size();i++){
mp[original[i]] = i ;
}

for (char i : s){
int idx = mp[i];
if (c=='R')
cout << original[idx-1];
else
cout << original[idx+1];
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
void fast ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

}
int main()
{
fast();
int n , m;
cin >>n >> m;
set<int>st;
for (int i=0;i<n;i++){
int x;
cin >> x;
while (x--){
int y;
cin >> y;
st.insert(y);
}
}
if (st.size()==m)
cout << "YES";
else cout << "NO";

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
void fast ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

}
int main()
{
fast();
int t;
cin >> t;
while (t--){
int n , r;
cin >> n >> r;
set<int>st;
for (int i=0 , x;i<n;i++){
cin >> x;
st.insert(x);
}
vector<int>v(st.begin() , st.end());
int d = 0 , cnt=0;
for (int i=v.size()-1 ;i>=0;i--){
if (v[i] - d > 0)
cnt++ ,d+=r ;
}
cout << cnt << "\n";
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <bits/stdc++.h>
using namespace std;
void fast ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

}
int main()
{
fast();
int q;
cin >> q;
set<pair<int,int>>m , p;
int id = 1;
while (q--){
int op;
cin >> op;
if (op==1){
int x;
cin >> x;
p.insert({-x , id}) ;
m.insert({id++ , x});
}
else if (op==2){
auto it = *m.begin();
p.erase({-it.second , it.first});
m.erase(it);
cout << it.first << " ";
}
else {
auto it = *p.begin();
m.erase({it.second , -it.first});
p.erase(it);
cout << it.second << " ";
}
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
void fast ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

}
int main()
{
fast();
int n, m;
cin >> n >> m;
map<int, int > mps, mpb;
while (n--)
{
char c ;
int p, num ;
cin >> c >> p >> num;
if (c=='S')
mps[p]+=num;
else mpb[p]+=num;
}
vector<pair<int,int>> b, s;
for (auto i : mpb)
{
b.push_back({i.first, i.second});
}
for (auto i : mps)
{
s.push_back({i.first, i.second});
}
sort(b.begin(),b.end());
sort(s.begin(),s.end());
reverse(b.begin(),b.end());
for (int i=min(m-1 , (int)s.size()-1);i>=0 ;i--){
cout << "S " << s[i].first << " " << s[i].second << el;
}
for (int i=0;i<b.size() && i<m;i++){
cout << "B " << b[i].first << " " << b[i].second <<el;
}


return 0;
}

0 comments on commit 277b786

Please sign in to comment.