├── README.md └── Solutions ├── Day-0.cpp ├── Day-1.cpp ├── Day-10.cpp ├── Day-11.cpp ├── Day-12.cpp ├── Day-13.cpp ├── Day-14.cpp ├── Day-15.cpp ├── Day-16.cpp ├── Day-17.cpp ├── Day-18.cpp ├── Day-19.cpp ├── Day-2.cpp ├── Day-20.cpp ├── Day-21.cpp ├── Day-22.cpp ├── Day-23.cpp ├── Day-24.cpp ├── Day-25.cpp ├── Day-26.cpp ├── Day-28.cpp ├── Day-29.cpp ├── Day-3.cpp ├── Day-4.cpp ├── Day-5.cpp ├── Day-6.cpp ├── Day-7.cpp ├── Day-8.cpp └── Day-9.cpp /README.md: -------------------------------------------------------------------------------- 1 | # Hackerrank-30-days-of-Code-Cpp 2 | These are the C++ solutions of http://hackerrank.com 's 30 days of Code 3 | 4 | For any Mistakes or errors, Contact me at Drigg3r@yandex.com 5 | -------------------------------------------------------------------------------- /Solutions/Day-0.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | //-------------------------------------------------------------------- 10 | 11 | 12 | int main() 13 | { 14 | 15 | string input_string; 16 | 17 | getline(cin, input_string); 18 | 19 | cout << "Hello, World." << endl; 20 | 21 | cout << input_string << endl; 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Solutions/Day-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int i = 4; 9 | double d = 4.0; 10 | string s = "HackerRank "; 11 | 12 | //----------------------------------------------------------------- 13 | 14 | 15 | int lo; 16 | string lo2; 17 | double lo3; 18 | cin >> lo >> lo3 >> lo2; 19 | 20 | cout << lo + i << endl; 21 | cout << lo3 + d << endl; 22 | cout << s << lo2 << endl; 23 | 24 | //--------------------------------------------------------------------- 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Solutions/Day-10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool desc(int i, int l){return (i > l);} 9 | 10 | int main(){ 11 | int n; 12 | cin >> n; 13 | vector ones; 14 | bitset<32> m(n); 15 | string ip = m.to_string(); 16 | int cnt = 0; 17 | for(int m = 0; m < ip.size(); ++m){ 18 | if(ip[m] == '1'){ 19 | ++cnt; 20 | } 21 | else{ 22 | ones.push_back(cnt); 23 | cnt = 0; 24 | } 25 | if(m == ip.size() - 1){ 26 | ones.push_back(cnt); 27 | } 28 | } 29 | sort(ones.begin(), ones.end(), desc); 30 | cout << ones.at(0) << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Solutions/Day-11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector >lmao; 8 | vector answers; 9 | 10 | bool desc(int i, int k){return i > k;} 11 | 12 | int TakeInput(int i, int m) 13 | { 14 | for(int f = 0; f < i; ++f){ 15 | vector temp; 16 | for(int a = 0; a < m; ++a){ 17 | int x; 18 | cin >> x; 19 | temp.push_back(x); 20 | } 21 | lmao.push_back(temp); 22 | } 23 | return 0; 24 | } 25 | 26 | void compute() 27 | { 28 | for(int i = 0; i < lmao.size() - 2; ++i){ 29 | for(int e = 0; e < lmao[i].size() - 2; ++e){ 30 | int sum = lmao[i][e] + lmao[i][e+1] + lmao[i][e+2] + lmao[i+1][e+1] +lmao[i+2][e] + lmao[i+2][e+1] + lmao[i+2][e+2]; 31 | answers.push_back(sum); 32 | } 33 | } 34 | } 35 | int main() 36 | { 37 | TakeInput(6, 6); 38 | compute(); 39 | sort(answers.begin(), answers.end(), desc); 40 | cout << answers.at(0) << endl; 41 | } 42 | -------------------------------------------------------------------------------- /Solutions/Day-12.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | class Person{ 8 | protected: 9 | string firstName; 10 | string lastName; 11 | int id; 12 | public: 13 | Person(string firstName, string lastName, int identification){ 14 | this->firstName = firstName; 15 | this->lastName = lastName; 16 | this->id = identification; 17 | } 18 | void printPerson(){ 19 | cout<< "Name: "<< lastName << ", "<< firstName <<"\nID: "<< id << "\n"; 20 | } 21 | 22 | }; 23 | 24 | //------------------------------------------------------------------------- 25 | 26 | class Student : public Person{ 27 | private: 28 | vector testScores; 29 | public: 30 | Student(string firstName, string lastName, int identification, vector scores) : Person(firstName, lastName, identification), testScores(scores) { } 31 | 32 | char calculate() { 33 | int average = 0; 34 | for(int i = 0; i < testScores.size(); i++) { 35 | average += testScores[i]; 36 | } 37 | average = average / testScores.size(); 38 | 39 | if(average >= 90) { 40 | return 'O'; // Outstanding 41 | } 42 | else if(average >= 80) { 43 | return 'E'; // Exceeds Expectations 44 | } 45 | else if(average >= 70) { 46 | return 'A'; // Acceptable 47 | } 48 | else if(average >= 55) { 49 | return 'P'; // Poor 50 | } 51 | else if(average >= 40) { 52 | return 'D'; // Dreadful 53 | } 54 | else { 55 | return 'T'; // Troll 56 | } 57 | } 58 | }; 59 | 60 | //------------------------------------------------------------------------- 61 | 62 | int main() { 63 | string firstName; 64 | string lastName; 65 | int id; 66 | int numScores; 67 | cin >> firstName >> lastName >> id >> numScores; 68 | vector scores; 69 | for(int i = 0; i < numScores; i++){ 70 | int tmpScore; 71 | cin >> tmpScore; 72 | scores.push_back(tmpScore); 73 | } 74 | Student* s = new Student(firstName, lastName, id, scores); 75 | s->printPerson(); 76 | cout << "Grade: " << s->calculate() << "\n"; 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /Solutions/Day-13.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | class Book{ 9 | protected: 10 | string title; 11 | string author; 12 | public: 13 | Book(string t,string a){ 14 | title=t; 15 | author=a; 16 | } 17 | virtual void display()=0; 18 | 19 | }; 20 | 21 | //-------------------------------------------------------------------- 22 | 23 | class MyBook : public Book { 24 | protected: 25 | int price; 26 | public: 27 | MyBook(string title, string author, int price) : Book(title, author), price(price) { } 28 | void display(){ 29 | cout << "Title: " << title << endl; 30 | cout << "Author: " << author << endl; 31 | cout << "Price: " << price << endl; 32 | } 33 | }; 34 | 35 | //--------------------------------------------------------------------- 36 | 37 | int main() { 38 | string title,author; 39 | int price; 40 | getline(cin,title); 41 | getline(cin,author); 42 | cin>>price; 43 | MyBook novel(title,author,price); 44 | novel.display(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Solutions/Day-14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class Difference { 10 | private: 11 | vector elements; 12 | 13 | public: 14 | int maximumDifference; 15 | 16 | //------------------------------------------------------------------------------------ 17 | 18 | Difference(vector elm) : elements(elm) {} 19 | void computeDifference(){ 20 | sort(elements.begin(), elements.end(), greater()); 21 | maximumDifference = elements.at(0) - elements.at(elements.size() - 1); 22 | } 23 | 24 | //-------------------------------------------------------------------------------------- 25 | 26 | }; // End of Difference class 27 | 28 | int main() { 29 | int N; 30 | cin >> N; 31 | 32 | vector a; 33 | 34 | for (int i = 0; i < N; i++) { 35 | int e; 36 | cin >> e; 37 | 38 | a.push_back(e); 39 | } 40 | 41 | Difference d(a); 42 | 43 | d.computeDifference(); 44 | 45 | cout << d.maximumDifference; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Solutions/Day-15.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Node 5 | { 6 | public: 7 | int data; 8 | Node *next; 9 | Node(int d){ 10 | data=d; 11 | next=NULL; 12 | } 13 | }; 14 | class Solution{ 15 | public: 16 | 17 | //------------------------------------------------------------ 18 | 19 | Node* insert(Node *head,int data) 20 | { 21 | if(head == NULL){ 22 | head = new Node(data); 23 | return head; 24 | } 25 | else if(head->next == NULL){ 26 | Node *temp = new Node(data); 27 | head->next = temp; 28 | return head; 29 | } 30 | else{ 31 | insert(head->next, data); 32 | } 33 | return head; 34 | } 35 | 36 | //-------------------------------------------------------------- 37 | 38 | void display(Node *head) 39 | { 40 | Node *start=head; 41 | while(start) 42 | { 43 | cout<data<<" "; 44 | start=start->next; 45 | } 46 | } 47 | }; 48 | int main() 49 | { 50 | Node* head=NULL; 51 | Solution mylist; 52 | int T,data; 53 | cin>>T; 54 | while(T-->0){ 55 | cin>>data; 56 | head=mylist.insert(head,data); 57 | } 58 | mylist.display(head); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Solutions/Day-16.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | string S; 8 | cin >> S; 9 | try{ 10 | int no; 11 | no = stoi(S); 12 | cout << no << endl; 13 | } 14 | catch(exception e){ 15 | cout << "Bad String" << endl; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/Day-17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | //------------------------------------------------------------------ 8 | 9 | class Calculator{ 10 | public: 11 | int power(int a, int b){ 12 | if(a < 0){ 13 | throw invalid_argument( "n and p should be non-negative" ); 14 | } 15 | if(b < 0){ 16 | throw invalid_argument( "n and p should be non-negative" ); 17 | } 18 | return pow(a, b); 19 | } 20 | }; 21 | 22 | //--------------------------------------------------------------------- 23 | 24 | int main() 25 | { 26 | Calculator myCalculator=Calculator(); 27 | int T,n,p; 28 | cin>>T; 29 | while(T-->0){ 30 | if(scanf("%d %d",&n,&p)==2){ 31 | try{ 32 | int ans=myCalculator.power(n,p); 33 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Solution { 8 | private: 9 | vectorstack; 10 | dequequeue; 11 | int p = 0; 12 | int q = 0; 13 | public: 14 | char pushCharacter(char c){ 15 | stack.push_back(c); 16 | return NULL; 17 | } 18 | char enqueueCharacter(char c){ 19 | queue.push_front(c); 20 | return NULL; 21 | } 22 | char popCharacter(){ 23 | return stack[p++]; 24 | } 25 | char dequeueCharacter(){ 26 | return queue[q++]; 27 | } 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /Solutions/Day-19.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | class AdvancedArithmetic{ 9 | public: 10 | virtual int divisorSum(int n)=0; 11 | }; 12 | 13 | //-------------------------------------------------------------------- 14 | 15 | class Calculator : public AdvancedArithmetic{ 16 | public: 17 | int divisorSum(int n){ 18 | vectordivisors; 19 | for(int i = 1; i <= n; ++i){ 20 | if(n % i == 0){ 21 | divisors.push_back(i); 22 | } 23 | } 24 | int sum = 0; 25 | for(auto m : divisors){ 26 | sum += m; 27 | } 28 | return sum; 29 | } 30 | }; 31 | 32 | //--------------------------------------------------------------- 33 | 34 | int main(){ 35 | int n; 36 | cin >> n; 37 | AdvancedArithmetic *myCalculator = new Calculator(); 38 | int sum = myCalculator->divisorSum(n); 39 | cout << "I implemented: AdvancedArithmetic\n" << sum; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Solutions/Day-2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | double x, y, z; 7 | cin >> x >> y >> z; 8 | double tip = x * y / 100; 9 | double tax = x * z / 100; 10 | double total = x + tip + tax; 11 | int total2 = total; 12 | cout << "The total meal cost is " << total2 << " dollars."; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Solutions/Day-20.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int calculate(vector &ab) 8 | { 9 | int allswaps = 0; 10 | while(1){ 11 | int tempswaps = 0; 12 | for(int i = 0; i < ab.size() - 1; ++i){ 13 | if(ab[i] > ab[i+1]){ 14 | swap(ab[i], ab[i+1]); 15 | ++tempswaps; 16 | } 17 | } 18 | if(tempswaps == 0){ 19 | break; 20 | } 21 | allswaps += tempswaps; 22 | } 23 | return allswaps; 24 | } 25 | 26 | int main() 27 | { 28 | int n; 29 | cin >> n; 30 | vector a; 31 | for(int a_i = 0;a_i < n;a_i++){ 32 | int p; 33 | cin >> p; 34 | a.push_back(p); 35 | } 36 | cout << "Array is sorted in " << calculate(a) << " swaps." << endl; 37 | cout << "First Element: " << a.at(0) << endl; 38 | cout << "Last Element: " << a.at(a.size() - 1) << endl; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Solutions/Day-21.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | //--------------------------------------------------------- 7 | 8 | template 9 | void printArray(vector array) { 10 | for(TP i : array){ 11 | cout << i << endl; 12 | } 13 | } 14 | 15 | //----------------------------------------------------- 16 | 17 | int main() { 18 | 19 | vector vInt{1, 2, 3}; 20 | vector vString{"Hello", "World"}; 21 | 22 | printArray(vInt); 23 | printArray(vString); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Solutions/Day-22.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Node{ 7 | public: 8 | int data; 9 | Node *left; 10 | Node *right; 11 | Node(int d){ 12 | data = d; 13 | left = NULL; 14 | right = NULL; 15 | } 16 | }; 17 | class Solution{ 18 | public: 19 | Node* insert(Node* root, int data) { 20 | if(root == NULL) { 21 | return new Node(data); 22 | } 23 | else { 24 | Node* cur; 25 | if(data <= root->data){ 26 | cur = insert(root->left, data); 27 | root->left = cur; 28 | } 29 | else{ 30 | cur = insert(root->right, data); 31 | root->right = cur; 32 | } 33 | 34 | return root; 35 | } 36 | } 37 | 38 | //--------------------------------------------------------------------- 39 | 40 | int getHeight(Node* root){ 41 | if(root == NULL){ 42 | return -1; 43 | } 44 | int ldepth = getHeight(root->left); 45 | int rdepth = getHeight(root->right); 46 | if(ldepth < rdepth){ 47 | return (rdepth + 1); 48 | }else {return ldepth +1;} 49 | } 50 | 51 | //----------------------------------------------------------------- 52 | 53 | }; //End of Solution 54 | 55 | int main() { 56 | Solution myTree; 57 | Node* root = NULL; 58 | int t; 59 | int data; 60 | 61 | cin >> t; 62 | 63 | while(t-- > 0){ 64 | cin >> data; 65 | root = myTree.insert(root, data); 66 | } 67 | int height = myTree.getHeight(root); 68 | cout << height; 69 | 70 | return 0; 71 | } 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Solutions/Day-23.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | class Node{ 9 | public: 10 | int data; 11 | Node *left,*right; 12 | Node(int d){ 13 | data=d; 14 | left=right=NULL; 15 | } 16 | }; 17 | class Solution{ 18 | public: 19 | Node* insert(Node* root, int data){ 20 | if(root==NULL){ 21 | return new Node(data); 22 | } 23 | else{ 24 | Node* cur; 25 | if(data<=root->data){ 26 | cur=insert(root->left,data); 27 | root->left=cur; 28 | } 29 | else{ 30 | cur=insert(root->right,data); 31 | root->right=cur; 32 | } 33 | return root; 34 | } 35 | } 36 | 37 | //----------------------------------------------------------------------------------- 38 | 39 | void levelOrder(Node *root){ 40 | int height = MaxHeight(root); 41 | for(int i = 0; i <= height; ++i){ 42 | ThisLevelTransversal(root, i); 43 | } 44 | } 45 | int MaxHeight(Node* root){ 46 | if(root == NULL){ 47 | return -1; 48 | } 49 | int ldepth = MaxHeight(root->left); 50 | int rdepth = MaxHeight(root->right); 51 | if(ldepth < rdepth){ 52 | return (rdepth + 1); 53 | }else {return ldepth +1;} 54 | } 55 | void ThisLevelTransversal(Node *root, int level){ 56 | if(root == NULL){return;} 57 | if (level == 0){ 58 | cout << root->data << " "; 59 | }else if (level > 0){ 60 | ThisLevelTransversal(root->left, level-1); 61 | ThisLevelTransversal(root->right, level-1); 62 | } 63 | 64 | } 65 | 66 | //------------------------------------------------------- 67 | 68 | };//End of Solution 69 | int main(){ 70 | Solution myTree; 71 | Node* root=NULL; 72 | int T,data; 73 | cin>>T; 74 | while(T-->0){ 75 | cin>>data; 76 | root= myTree.insert(root,data); 77 | } 78 | myTree.levelOrder(root); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /Solutions/Day-24.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | class Node 9 | { 10 | public: 11 | int data; 12 | Node *next; 13 | Node(int d){ 14 | data=d; 15 | next=NULL; 16 | } 17 | }; 18 | class Solution{ 19 | public: 20 | 21 | //---------------------------------------------------------------------- 22 | 23 | Node* removeDuplicates(Node *head) 24 | { 25 | Node *cur = head; 26 | Node *helper; 27 | if(cur == NULL){ 28 | return head; 29 | } 30 | while(cur->next != NULL){ 31 | if(cur->data == cur->next->data){ 32 | cur->next = cur->next->next; 33 | } 34 | else cur = cur->next; 35 | } 36 | return head; 37 | } 38 | 39 | //--------------------------------------------------------------------------- 40 | 41 | Node* insert(Node *head,int data) 42 | { 43 | Node* p=new Node(data); 44 | if(head==NULL){ 45 | head=p; 46 | 47 | } 48 | else if(head->next==NULL){ 49 | head->next=p; 50 | 51 | } 52 | else{ 53 | Node *start=head; 54 | while(start->next!=NULL){ 55 | start=start->next; 56 | } 57 | start->next=p; 58 | 59 | } 60 | return head; 61 | 62 | 63 | } 64 | void display(Node *head) 65 | { 66 | Node *start=head; 67 | while(start) 68 | { 69 | cout<data<<" "; 70 | start=start->next; 71 | } 72 | } 73 | }; 74 | 75 | int main() 76 | { 77 | Node* head=NULL; 78 | Solution mylist; 79 | int T,data; 80 | cin>>T; 81 | while(T-->0){ 82 | cin>>data; 83 | head=mylist.insert(head,data); 84 | } 85 | head=mylist.removeDuplicates(head); 86 | 87 | mylist.display(head); 88 | 89 | } 90 | -------------------------------------------------------------------------------- /Solutions/Day-25.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | bool CheckPrime(int n){ 9 | if(n == 1){return false;} 10 | int m; 11 | m = sqrt(n); 12 | bool isprime = true; 13 | for(int i = 2; i <= m; ++i){ 14 | if(n % i == 0){ 15 | isprime = false; 16 | break; 17 | } 18 | } 19 | return isprime; 20 | } 21 | 22 | int main() { 23 | int p; 24 | cin >> p; 25 | for(int i = 0; i < p; ++i){ 26 | int m; 27 | cin >> m; 28 | if(CheckPrime(m)){ 29 | cout << "Prime" << endl; 30 | }else cout << "Not prime" << endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Solutions/Day-26.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int fine; 11 | int retDay, retMonth, retYear; 12 | int expDay, expMonth, expYear; 13 | cin >> retDay >> retMonth >> retYear; 14 | cin >> expDay >> expMonth >> expYear; 15 | if(retYear < expYear){ 16 | fine = 0; 17 | }else if(retYear == expYear){ 18 | if(retMonth < expMonth){ 19 | fine = 0; 20 | }else if(retMonth == expMonth){ 21 | if(retDay <= expDay){ 22 | fine = 0; 23 | }else fine = (retDay - expDay) * 15; 24 | }else fine = (retMonth - expMonth) * 500; 25 | }else fine = 10000; 26 | cout << fine << endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Solutions/Day-28.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | vectorsorted; 9 | 10 | bool ascending(string i, string m){return i < m;} 11 | 12 | void compute(vector email, vector name){ 13 | for(int i = 0; i < email.size(); ++i){ 14 | if(email[i].find("@gmail.com") != std::string::npos){ 15 | sorted.push_back(name[i]); 16 | } 17 | } 18 | sort(sorted.begin(), sorted.end(), ascending); 19 | } 20 | 21 | int main(){ 22 | vectormails; 23 | vectornames; 24 | int N; 25 | cin >> N; 26 | for(int a0 = 0; a0 < N; a0++){ 27 | string firstName; 28 | string emailID; 29 | cin >> firstName >> emailID; 30 | names.push_back(firstName); 31 | mails.push_back(emailID); 32 | } 33 | compute(mails, names); 34 | for(auto m : sorted){ 35 | cout << m << endl; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Solutions/Day-29.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int outAnd(int a, int b){ 7 | vectorlol; 8 | for(int i = 1; i <= a; ++i){ 9 | lol.push_back(i); 10 | } 11 | int max = 0; 12 | for(int i = 0; i < lol.size(); ++i){ 13 | for(int p = i + 1; p < lol.size(); ++p){ 14 | int anded = lol[i] & lol[p]; 15 | if((anded > max) && (anded < b) ){ 16 | max = anded; 17 | } 18 | } 19 | } 20 | return max; 21 | } 22 | 23 | int main(){ 24 | int t; 25 | cin >> t; 26 | for(int a0 = 0; a0 < t; a0++){ 27 | int n; 28 | int k; 29 | cin >> n >> k; 30 | cout << outAnd(n, k) << endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Solutions/Day-3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | int N; 7 | cin >> N; 8 | if(N%2 != 0 || (N%2 == 0) && N >= 6 && N <= 20){ 9 | cout << "Weird" << endl; 10 | }else cout << "Not Weird" << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/Day-4.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | #include 3 | 4 | //-------------------------------------------------------------------------------------------------- 5 | 6 | class Person{ 7 | public: 8 | int age; 9 | Person(int initialAge); 10 | void amIOld(); 11 | void yearPasses(); 12 | }; 13 | 14 | Person::Person(int initialAge){ 15 | if(initialAge < 0){ 16 | age = 0; 17 | cout << "Age is not valid, setting age to 0." << endl; 18 | }else age = initialAge; 19 | 20 | } 21 | 22 | void Person::amIOld(){ 23 | if(age < 13){ 24 | cout << "You are young." << endl; 25 | } 26 | else if(age >= 13 && age < 18){ 27 | cout << "You are a teenager." << endl; 28 | }else cout << "You are old." << endl; 29 | 30 | } 31 | 32 | void Person::yearPasses(){ 33 | age += 1; 34 | 35 | } 36 | 37 | //------------------------------------------------------------------------- 38 | 39 | int main(){ 40 | int t; 41 | int age; 42 | cin >> t; 43 | for(int i=0; i < t; i++) { 44 | cin >> age; 45 | Person p(age); 46 | p.amIOld(); 47 | for(int j=0; j < 3; j++) { 48 | p.yearPasses(); 49 | } 50 | p.amIOld(); 51 | 52 | cout << '\n'; 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Solutions/Day-5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | int n; 8 | cin >> n; 9 | for(int i = 1; i <= 10; ++i){ 10 | cout << n << " x " << i << " = " << n * i << endl; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Solutions/Day-6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | for(int i = 0; i < n; ++i){ 10 | string m; 11 | cin >> m; 12 | for(int k = 0; k < m.size(); k +=2){ 13 | cout << m[k]; 14 | } 15 | cout << " "; 16 | for(int t = 1; t < m.size(); t +=2){ 17 | cout << m[t]; 18 | } 19 | cout << endl; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/Day-7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | int main(){ 8 | int n; 9 | cin >> n; 10 | vector arr(n); 11 | for(int arr_i = 0;arr_i < n;arr_i++){ 12 | cin >> arr[arr_i]; 13 | } 14 | for (int i = arr.size() - 1; i >= 0; --i){ 15 | cout << arr[i] << " "; 16 | } 17 | cout << endl; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/Day-8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() { 8 | int x; 9 | cin >> x; 10 | map all; 11 | for(int i = 0; i < x; ++i){ 12 | string s, p; 13 | cin >> s >> p; 14 | all[s] = p; 15 | } 16 | string h; 17 | while(cin >> h){ 18 | if(all.find(h) == all.end()){ 19 | cout << "Not found" << endl; 20 | } 21 | else{ 22 | cout << h << "=" << all.at(h) << endl; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Solutions/Day-9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int factorial(int y) 6 | { 7 | if (y == 1){ 8 | return 1; 9 | } 10 | else{ 11 | return y * factorial(y - 1); 12 | } 13 | } 14 | 15 | int main() { 16 | int x; 17 | cin >> x; 18 | cout << factorial(x) << endl; 19 | return 0; 20 | } 21 | --------------------------------------------------------------------------------