Commit 2530116e38e4d5deb3d47a0ef1b10b16562b9467

Authored by Ronaldo
1 parent 743b077f4a
Exists in main

Update.

Showing 4 changed files with 168 additions and 0 deletions Inline Diff

SearchingSortingandBasicDataStructures/InbuiltSorting/Problem1/GeeksAndGroceries.cpp View file @ 2530116
File was created 1 //
2 // Created by ronal on 2/11/2023.
3 // Problem Description link.
4 // https://practice.geeksforgeeks.org/problems/geeks-and-groceries/0
5
6 #include <bits/stdc++.h>
7
8 using namespace std;
9
10 void PrintProducts(vector<pair<int, string>> &P, int qnt){
11 vector<string> S;
12
13 for(auto value : P){
14 if(S.size() < qnt){
15 S.push_back(value.second);
16 }else{
17 break;
18 }
19 }
20
21 for(auto products : S){
22 cout << products << " ";
23 }
24 cout << "\n";
25 }
26 int main() {
27 vector<pair<int, string>> produtos;
28 int tests, qnt_pro, choose_produ, price;
29 string value;
30
31 cin >> tests;
32 for(int i = 0; i < tests; i++){
33 cin >> qnt_pro >> choose_produ;
34
35 for(int j = 0; j < qnt_pro; j++){
36 cin >> value >> price;
37 produtos.emplace_back(price, value);
SearchingSortingandBasicDataStructures/InbuiltSorting/Problem2/KLargerValues.cpp View file @ 2530116
File was created 1 //
2 // Created by ronal on 2/11/2023.
3 // Problem Description Link.
4 // https://practice.geeksforgeeks.org/problems/k-larger-values/0
5
6 #include <bits/stdc++.h>
7 using namespace std;
8
9 void PrintValuesMoreThanKey(vector<int> &v, int key){
10 for(int i = 0; i < key; i++){
11 cout << v[i] << " ";
12 }
13 cout << "\n";
14 v.clear();
15 }
16 int main() {
17 vector<int> v;
18 int tests, size, key, value;
19
20 cin >> tests;
21 for(int i = 0; i < tests; i++){
22 cin >> size >> key;
23 for(int j = 0; j < size; j++){
24 cin >> value;
25 v.push_back(value);
26 }
27
28 sort(v.begin(), v.end(), greater<int>());
SearchingSortingandBasicDataStructures/InbuiltSorting/Problem3/KLargerValuesTwo.cpp View file @ 2530116
File was created 1 //
2 // Created by ronal on 2/11/2023.
3 // Problem Decription Link.
4 // https://practice.geeksforgeeks.org/problems/k-larger-values-1611827113/0
5
6 #include <bits/stdc++.h>
7
8 using namespace std;
9
10 void PrintSet(set<int, greater<>> &S, int key){
11 vector<int> v;
12 for(auto value : S){
13 v.push_back(value);
14 }
15
16 if(v.size() < key){
17 cout << "-1";
18 }else{
19 for(int i = 0; i < key; i++){
20 cout << v[i] << " ";
21 }
22 }
23 cout << "\n";
24 }
25 int main() {
26 set<int, greater<>> S;
27 int tests, size, key, value;
28 cin >> tests;
29 for(int i = 0; i < tests; i++){
30 cin >> size >> key;
31 for(int j = 0; j < size; j++){
32 cin >> value;
33 S.insert(value);
34 }
35 PrintSet(S, key);
SearchingSortingandBasicDataStructures/InbuiltSorting/Problem4/KConsecutiveOddElements.cpp View file @ 2530116
File was created 1 //
2 // Created by ronal on 2/11/2023.
3 // Problem Description Link.
4 // https://practice.geeksforgeeks.org/problems/k-consecutive-odd-elements/0
5
6 #include <bits/stdc++.h>
7 using namespace std;
8
9 void PrintResult(vector<int> &v, int key){
10 int count = 0;
11 for(int i = 0; i < v.size(); i++){
12 if(v[i] % 2 != 0){
13 count++;
14 }else{
15 count = 0;
16 }
17 if(count == key){
18 break;
19 }else{
20 continue;
21 }
22 }
23
24 if(count == key){
25 cout << "yes";
26 }else{
27 cout << "no";
28 }
29 cout << "\n";
30
31 }
32
33 int main() {
34 vector<int> v;
35 int tests, size, key, value;
36
37 cin >> tests;
38 for(int i = 0; i < tests; i++){
39 cin >> size >> key;
40
41 for(int j = 0; j < size; j++){
42 cin >> value;
43 v.push_back(value);