From 2185c2ce0ef4843c445de8dcd43b1a684a3ce63e Mon Sep 17 00:00:00 2001 From: ankit7023 <68903835+ankit7023@users.noreply.github.com> Date: Sun, 3 Oct 2021 19:43:14 +0530 Subject: [PATCH 1/5] Create a.cpp --- CodeChef/a.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CodeChef/a.cpp diff --git a/CodeChef/a.cpp b/CodeChef/a.cpp new file mode 100644 index 0000000..ba27350 --- /dev/null +++ b/CodeChef/a.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() +{ + int t; + cin >> t; + while(t--){ + int X, A, B; + cin >> X >> A >> B; + int ans = (A*10) + (100-X)*(B*10); + cout << ans << endl; + } + + return 0; +} From a77f198dc7d2800739bf102da1cf9c2ae4dfb41c Mon Sep 17 00:00:00 2001 From: ankit7023 <68903835+ankit7023@users.noreply.github.com> Date: Sun, 3 Oct 2021 19:44:59 +0530 Subject: [PATCH 2/5] Create gfgAnk.cpp --- gfg/gfgAnk.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 gfg/gfgAnk.cpp diff --git a/gfg/gfgAnk.cpp b/gfg/gfgAnk.cpp new file mode 100644 index 0000000..5c96fff --- /dev/null +++ b/gfg/gfgAnk.cpp @@ -0,0 +1,102 @@ +//Initial Template for C +#include +#include + +struct Node +{ + int data; + struct Node *next; + +}*start; + +void insert(); +void display(struct Node *head); + + // } Driver Code Ends +//User function Template for C + + + +struct Node* reverseList(struct Node *head) + { + struct Node* current = head; + struct Node* prev = NULL; + struct Node* nextptr = NULL; + + while(current != NULL){ + nextptr = current->next; + current->next = prev; + prev = current; + current = nextptr; + } + + return prev; + + // if(head->next == NULL){ + // return head; + // } + + // struct Node* newHead = reverseList(head->next); + // head->next->next = head; + // head->next = NULL; + // return newHead; + } + +// { Driver Code Starts. + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + start=NULL; + insert(); + start = reverseList(start); + display(start); + printf("\n"); + } + return 0; + +} + + + void insert() + { + int n,value,i; + scanf("%d",&n); + struct Node *temp; + for(i=0;idata=value; + start->next=NULL; + temp=start; + continue; + } + else + { + temp->next= (struct Node *) malloc( sizeof(struct Node) ); + temp=temp->next; + temp->data=value; + temp->next=NULL; + } + } + } + + void display(struct Node *head) +{ + while(head!=NULL) + { + printf("%d ",head->data); + head=head->next; + } +} + + + + + // } Driver Code Ends From 4c5e06c5446e160442b6ac73617a76dbd78e6769 Mon Sep 17 00:00:00 2001 From: ankit7023 <68903835+ankit7023@users.noreply.github.com> Date: Sun, 3 Oct 2021 19:46:01 +0530 Subject: [PATCH 3/5] Create Ankit.cpp --- LeetCode/Ankit.cpp | 146 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 LeetCode/Ankit.cpp diff --git a/LeetCode/Ankit.cpp b/LeetCode/Ankit.cpp new file mode 100644 index 0000000..86f1eb8 --- /dev/null +++ b/LeetCode/Ankit.cpp @@ -0,0 +1,146 @@ +//Initial Template for C++ + +#include +using namespace std; + +/* A binary tree node has data, pointer to left child + and a pointer to right child */ +struct Node +{ + int data; + struct Node* left; + struct Node* right; + + Node(int x){ + data = x; + left = right = NULL; + } +}; + +// Function to Build Tree +Node *buildTree(string str) { + // Corner Case + if (str.length() == 0 || str[0] == 'N') + return NULL; + + // Creating vector of strings from input + // string after spliting by space + vector ip; + + istringstream iss(str); + for (string str; iss >> str;) + ip.push_back(str); + + // Create the root of the tree + Node *root = new Node(stoi(ip[0])); + + // Push the root to the queue + queue queue; + queue.push(root); + + // Starting from the second element + int i = 1; + while (!queue.empty() && i < ip.size()) { + + // Get and remove the front of the queue + Node *currNode = queue.front(); + queue.pop(); + + // Get the current node's value from the string + string currVal = ip[i]; + + // If the left child is not null + if (currVal != "N") { + + // Create the left child for the current node + currNode->left = new Node(stoi(currVal)); + + // Push it to the queue + queue.push(currNode->left); + } + + // For the right child + i++; + if (i >= ip.size()) + break; + currVal = ip[i]; + + // If the right child is not null + if (currVal != "N") { + + // Create the right child for the current node + currNode->right = new Node(stoi(currVal)); + + // Push it to the queue + queue.push(currNode->right); + } + i++; + } + + return root; +} + +void mirror(struct Node* node); + +/* Helper function to test mirror(). Given a binary + search tree, print out its data elements in + increasing sorted order.*/ +void inOrder(struct Node* node) +{ + if (node == NULL) + return; + + inOrder(node->left); + printf("%d ", node->data); + + inOrder(node->right); +} + + + +/* Driver program to test size function*/ +int main() { + int tc; + scanf("%d ", &tc); + while (tc--) { + string str; + getline(cin, str); + Node *root = buildTree(str); + mirror(root); + inOrder(root); + cout << "\n"; + } + + + return 0; +}// } Driver Code Ends + + +//function Template for C++ + +/* A binary tree node has data, pointer to left child + and a pointer to right child / +struct Node +{ + int data; + struct Node* left; + struct Node* right; + + Node(int x){ + data = x; + left = right = NULL; + } +}; */ + +/* Should convert tree to its mirror */ +void mirror(Node* node) +{ + if(node == NULL){ + return; + } + Node* temp = node->right; + node->right = node->left; + node->left = temp; + mirror(node->left); + mirror(node->right); +} From c2d21267dbd0695cb934e4349a1e76c20dcde95e Mon Sep 17 00:00:00 2001 From: ankit7023 <68903835+ankit7023@users.noreply.github.com> Date: Sun, 3 Oct 2021 19:49:55 +0530 Subject: [PATCH 4/5] Create rightViewofBinaryTree.cpp --- LeetCode/rightViewofBinaryTree.cpp | 161 +++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 LeetCode/rightViewofBinaryTree.cpp diff --git a/LeetCode/rightViewofBinaryTree.cpp b/LeetCode/rightViewofBinaryTree.cpp new file mode 100644 index 0000000..829f552 --- /dev/null +++ b/LeetCode/rightViewofBinaryTree.cpp @@ -0,0 +1,161 @@ +#include +using namespace std; + +// Tree Node +struct Node +{ + int data; + Node* left; + Node* right; +}; +// Utility function to create a new Tree Node +Node* newNode(int val) +{ + Node* temp = new Node; + temp->data = val; + temp->left = NULL; + temp->right = NULL; + + return temp; +} + + + // } Driver Code Ends +/* A binary tree node has data, pointer to left child + and a pointer to right child +struct Node +{ + int data; + struct Node* left; + struct Node* right; + + Node(int x){ + data = x; + left = right = NULL; + } +}; */ + +// Should return right view of tree +class Solution +{ + public: + //Function to return list containing elements of right view of binary tree. +vector rightView(Node *root){ + vector v; + if(root == NULL){ + return v; + } + queue q; + q.push(root); + int flag; + while(q.size() != 0){ + int n = q.size(); + while(n--){ + Node* curr = q.front(); + q.pop(); + if(n == 0){ + v.push_back(curr->data); + } + if(curr->left){ + q.push(curr->left); + } + if(curr->right){ + q.push(curr->right); + } + } + } + return v; +} +}; + + + +// { Driver Code Starts. + +// Function to Build Tree +Node* buildTree(string str) +{ + // Corner Case + if(str.length() == 0 || str[0] == 'N') + return NULL; + + // Creating vector of strings from input + // string after spliting by space + vector ip; + + istringstream iss(str); + for(string str; iss >> str; ) + ip.push_back(str); + + // Create the root of the tree + Node* root = newNode(stoi(ip[0])); + + // Push the root to the queue + queue queue; + queue.push(root); + + // Starting from the second element + int i = 1; + while(!queue.empty() && i < ip.size()) { + + // Get and remove the front of the queue + Node* currNode = queue.front(); + queue.pop(); + + // Get the current node's value from the string + string currVal = ip[i]; + + // If the left child is not null + if(currVal != "N") { + + // Create the left child for the current node + currNode->left = newNode(stoi(currVal)); + + // Push it to the queue + queue.push(currNode->left); + } + + // For the right child + i++; + if(i >= ip.size()) + break; + currVal = ip[i]; + + // If the right child is not null + if(currVal != "N") { + + // Create the right child for the current node + currNode->right = newNode(stoi(currVal)); + + // Push it to the queue + queue.push(currNode->right); + } + i++; + } + + return root; +} + + +int main() { + int t; + string tc; + getline(cin,tc); + t=stoi(tc); + while(t--) + { + string s; + getline(cin,s); + Node* root = buildTree(s); + + Solution ob; + vector vec = ob.rightView(root); + for(int x : vec){ + cout< Date: Sun, 3 Oct 2021 21:58:13 +0530 Subject: [PATCH 5/5] Create Redalert and imdb --- CodeChef/IMDB.cpp | 36 ++++++++++++++++++++++++++++++++++ CodeChef/REDALERT.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 CodeChef/IMDB.cpp create mode 100644 CodeChef/REDALERT.cpp diff --git a/CodeChef/IMDB.cpp b/CodeChef/IMDB.cpp new file mode 100644 index 0000000..8803446 --- /dev/null +++ b/CodeChef/IMDB.cpp @@ -0,0 +1,36 @@ +/* +Codechef Problem Name: Motivation +Codechef Problem Code: IMDB +Codechef Problem Link: https://www.codechef.com/problems/IMDB +*/ + +#include +#include +#define ll long long +using namespace std; + +int main() { + ll int t; + cin>>t; + while(t--){ + ll int x, n; + cin >> n >> x; + ll int s[n], r[n], max; + for(ll int i=0; i>s[i]>>r[i]; + } + if(n>=1 && s[0]<=x){ + max=r[0]; + } + else{ + max=0; + } + for(ll int i=1; imax && s[i]<=x){ + max=r[i]; + } + } + cout< +#include +#include +#include + +using namespace std; + +int main(){ + int t; + cin >> t; + while(t--){ + int n, d, h, u=0; + string ans = "NO"; + cin>>n>>d>>h; + int A[n]; + for(int i=0; i> A[i]; + } + for(int j=0; j0){ + u+=A[j]; + } + else{ + if(uh){ + ans = "YES"; + break; + } + } + cout << ans << endl; + } + return 0; +} \ No newline at end of file