diff --git a/December 01/c++_Surendersahk_Cricmetric.cpp b/December 01/c++_Surendersahk_Cricmetric.cpp new file mode 100644 index 0000000..e16aab7 --- /dev/null +++ b/December 01/c++_Surendersahk_Cricmetric.cpp @@ -0,0 +1,36 @@ +//There are five batsmen in the match. Their runs are 20, 35, 40, 15, and 25. The total runs scored by the team are 135. Batsman number 3 (index 2) scored the highest number of runs, which is 40. + +#include + +using namespace std; + +int main(){ + int n,arr[100],sum=0; + cout << "Enter How many batsmen in the match :\n"<< endl; + cin >>n; + + cout << "Enter the runs :\n"<< endl; + + for(int i=0;i> arr[i]; + } + + for(int i=0;imax){ + max=arr[i]; + index = i; + + } + } + cout << "\nThe batsman at index "<< index <<" scored the highest number of runs , which is "< +#include + +int main() { + std::vector array = {2, 4, 5, 2, 6, 7, 2, 8, 2}; + int size = array.size(); + + int numCount; + std::cout << "Enter the number of values you want to find frequencies for: "; + std::cin >> numCount; + + std::vector numbersToFind(numCount); + std::cout << "Enter the values you want to find frequencies for, separated by spaces: "; + for (int i = 0; i < numCount; ++i) { + std::cin >> numbersToFind[i]; + } + + for (int i = 0; i < numCount; ++i) { + int frequency = 0; + int num = numbersToFind[i]; + + for (int j = 0; j < size; ++j) { + if (array[j] == num) { + frequency++; + } + } + + std::cout << "The frequency of " << num << " is: " << frequency << std::endl; + } + + return 0; +} diff --git a/December 03/C++_Surendersahk_Sunburnt.cpp b/December 03/C++_Surendersahk_Sunburnt.cpp new file mode 100644 index 0000000..a995c0d --- /dev/null +++ b/December 03/C++_Surendersahk_Sunburnt.cpp @@ -0,0 +1,30 @@ +#include + +using namespace std; + +int main(){ + int h[10],n; + int max= 0; + + cout <<"\nEnter how many elements(buildings)"<< endl; + cin>>n; + + cout << "\nEnter the height of the buildings"<< endl; + for(int i=0;i>h[i]; + + } + for(int i=0;imax){ + max=h[i]; + + } + cout <<"max:"<< max<< endl; + } + + int size = sizeof(max); + + cout << "size is :"<< size << endl; + + +} \ No newline at end of file diff --git a/December 04/C++_Surendersahk_Mirror Magic.cpp b/December 04/C++_Surendersahk_Mirror Magic.cpp new file mode 100644 index 0000000..c486b38 --- /dev/null +++ b/December 04/C++_Surendersahk_Mirror Magic.cpp @@ -0,0 +1,40 @@ +#include +#include + +bool isPalindrome(const std::string& str) { + int left = 0; + int right = str.length() - 1; + + while (left < right) { + if (str[left] != str[right]) { + return false; + } + left++; + right--; + } + + return true; +} + +void extractPalindromes(const std::string& input) { + std::cout << "Palindromic substrings in '" << input << "':\n"; + + for (size_t i = 0; i < input.length(); ++i) { + for (size_t j = i + 1; j <= input.length(); ++j) { + std::string substring = input.substr(i, j - i); + if (isPalindrome(substring) && substring.length() > 1) { + std::cout << substring << std::endl; + } + } + } +} + +int main() { + std::string input; + std::cout << "Enter a string: "; + std::cin >> input; + + extractPalindromes(input); + + return 0; +} diff --git a/December 05/C++_Surendersahk_Peaky Blinders.cpp b/December 05/C++_Surendersahk_Peaky Blinders.cpp new file mode 100644 index 0000000..ba506a3 --- /dev/null +++ b/December 05/C++_Surendersahk_Peaky Blinders.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main(){ + int arr[10],n,sum=0,res,avg_ans; + + cout << "Enter how many elements :"<< endl; + cin>>n; + cout <<"Enter the elements in the array "<< endl; + for(int i=0;i>arr[i]; + sum +=arr[i]; + } + + res = sum/n; + cout << "res:"< +#include +#include +#include +#include +#include + +using namespace std; + +// Function to check if two words differ by only one character +bool isAdjacent(const string& a, const string& b) { + int diffCount = 0; + for (size_t i = 0; i < a.length(); ++i) { + if (a[i] != b[i]) { + if (++diffCount > 1) { + return false; + } + } + } + return diffCount == 1; +} + +// Perform BFS to find the shortest path +vector findOptimalSequence(const vector& words, const string& start, const string& end) { + unordered_map> adjList; + + // Create adjacency list + for (size_t i = 0; i < words.size(); ++i) { + for (size_t j = i + 1; j < words.size(); ++j) { + if (isAdjacent(words[i], words[j])) { + adjList[words[i]].push_back(words[j]); + adjList[words[j]].push_back(words[i]); + } + } + } + + unordered_map parent; + queue q; + q.push(start); + parent[start] = ""; + + while (!q.empty()) { + string current = q.front(); + q.pop(); + + if (current == end) { + break; + } + + for (const string& neighbor : adjList[current]) { + if (parent.find(neighbor) == parent.end()) { + parent[neighbor] = current; + q.push(neighbor); + } + } + } + + // Reconstruct the optimal sequence + vector sequence; + string current = end; + while (current != "") { + sequence.push_back(current); + current = parent[current]; + } + + reverse(sequence.begin(), sequence.end()); + return sequence; +} + +int main() { + vector encodedWords = {"co", "cade", "cade", "cate", "cart", "mart"}; + string startWord = "code"; + string endWord = "mart"; + + vector sequence = findOptimalSequence(encodedWords, startWord, endWord); + + if (sequence.empty() || sequence[0] != startWord || sequence.back() != endWord) { + cout << "No valid sequence found." << endl; + } else { + cout << "Optimal Sequence:" << endl; + for (const string& word : sequence) { + cout << word << " "; + } + cout << endl; + } + + return 0; +} diff --git a/December 07/C++_Surendersahk_Babyblocks.cpp b/December 07/C++_Surendersahk_Babyblocks.cpp new file mode 100644 index 0000000..fc5cc30 --- /dev/null +++ b/December 07/C++_Surendersahk_Babyblocks.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; + +int main (){ + + int diagonal,diameter,width ,height,rad_of_circle,square; + + cout <<"Enter the value of width :"; + cin>>width; + + cout <<"\nEnter the value of height :"; + cin>>height; + + square= pow(width,2)+pow(height,2); + + diagonal=sqrt(square); + + cout << diagonal<< endl; + + cout <<"\nEnter the value of radius of the circle :"; + cin>>rad_of_circle; + + diameter=rad_of_circle*2; + + if(diagonal<=diameter){ + cout<< "true"<< endl; + + } + else{ + cout << "false" << endl; + } + + + +} \ No newline at end of file diff --git a/December 08/C++_Surendersahk_The Enchanted Forest.cpp b/December 08/C++_Surendersahk_The Enchanted Forest.cpp new file mode 100644 index 0000000..731c45b --- /dev/null +++ b/December 08/C++_Surendersahk_The Enchanted Forest.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +using namespace std; + +int main(){ + + string s; + + cout << "Enter the string :"; + cin>>s; + + for(size_t i=0;i +#include +#include +using namespace std; + +int main(){ + + string s; + int count=0; + + cout << "ENter the string s : "; + cin>>s; + + + + for( char str : s){ + if(isupper(str)){ + + } + count++; + } + cout << "The letter is " << count<< endl; + + +} \ No newline at end of file diff --git a/December 10/C++_Surendersahk_Forgotpassword.cpp b/December 10/C++_Surendersahk_Forgotpassword.cpp new file mode 100644 index 0000000..b2168ba --- /dev/null +++ b/December 10/C++_Surendersahk_Forgotpassword.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + + +int main() { + // Sample data representing empname column values + std::string name; + std::vector empnames; + std::cout << "Enter the string names :"<< std::endl; + for(size_t i=0;i<3;i++){ + + std::cin>>name; + empnames.push_back(name); + +} + int start,end; + std::cout << "Start :"; + std::cin>>start; + + std::cout << "end:"; + std::cin>>end; + // Retrieve substring from empname column for each row + for (const std::string& empname : empnames) { + if (empname.length() >= 3) { // Check if the string length is at least 3 to avoid out-of-range issues + + std::string substring = empname.substr(start,end); // Extract two characters starting from the second character + std::cout << "Substring for " << empname << ": " << substring << std::endl; + } else { + std::cout << "Substring for " << empname << ": String too short" << std::endl; + } + } + + return 0; +} diff --git a/December 11/C++_Surendersahk_Coder of Conversions.cpp b/December 11/C++_Surendersahk_Coder of Conversions.cpp new file mode 100644 index 0000000..1d958e7 --- /dev/null +++ b/December 11/C++_Surendersahk_Coder of Conversions.cpp @@ -0,0 +1,20 @@ +#include +#include // For binary representation + +// Function to add two integers and return the sum in binary +std::string addAndConvertToBinary(int num1, int num2) { + int sum = num1 + num2; + return std::bitset(sum).to_string(); // Convert sum to binary string +} + +int main() { + int number1 = 1; + int number2 =1 ; + + std::string binarySum = addAndConvertToBinary(number1, number2); + + std::cout << "Sum of " << number1 << " and " << number2 << " in binary is: " << binarySum << std::endl; + + return 0; +} + diff --git a/December 12/C++_Surendersahk_TheHeist.cpp b/December 12/C++_Surendersahk_TheHeist.cpp new file mode 100644 index 0000000..cdb7134 --- /dev/null +++ b/December 12/C++_Surendersahk_TheHeist.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +int main() { + std::vector Box1 = {"Emerald", "Ruby", "Bronze", "Silver"}; + std::vector Box2 = {"Gold", "Diamond", "Ruby", "Copper"}; + std::vector Box3 = {"Ruby", "Platinum", "Bronze", "Silver"}; + + // Check if Box2 contains "Gold" + if (std::find(Box2.begin(), Box2.end(), "Ruby") != Box2.end()) { + std::cout << "Box2 contains Gold" << std::endl; + } else { + std::cout << "Box2 does not contain Gold" << std::endl; + } + + return 0; +} diff --git a/December 13/C++_Surendersahk_Call Cipher.cpp b/December 13/C++_Surendersahk_Call Cipher.cpp new file mode 100644 index 0000000..4a75890 --- /dev/null +++ b/December 13/C++_Surendersahk_Call Cipher.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +int main() { + std::string encodedNumber; + std::cout << "Enter the letter-encoded phone number: "; + std::cin >> encodedNumber; + + std::string decodedNumber = ""; + + for (char c : encodedNumber) { + if (std::isalpha(c)) { + c = std::tolower(c); + if (c >= 'a' && c <= 'c') { + decodedNumber += "2"; + } else if (c >= 'd' && c <= 'f') { + decodedNumber += "3"; + } else if (c >= 'g' && c <= 'i') { + decodedNumber += "4"; + } else if (c >= 'j' && c <= 'l') { + decodedNumber += "5"; + } else if (c >= 'm' && c <= 'o') { + decodedNumber += "6"; + } else if (c >= 'p' && c <= 's') { + decodedNumber += "7"; + } else if (c >= 't' && c <= 'v') { + decodedNumber += "8"; + } else if (c >= 'w' && c <= 'z') { + decodedNumber += "9"; + } + } else { + decodedNumber += c; + } + } + + std::cout << "Decoded phone number: " << decodedNumber << std::endl; + + return 0; +} diff --git a/December 14/C++_Surendersahk_Call of Justice.cpp b/December 14/C++_Surendersahk_Call of Justice.cpp new file mode 100644 index 0000000..054d816 --- /dev/null +++ b/December 14/C++_Surendersahk_Call of Justice.cpp @@ -0,0 +1,145 @@ +#include +#include +#include + +struct TreeNode { + int val; + TreeNode* left; + TreeNode* right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +void mapNodesToParents(TreeNode* node, std::unordered_map& parents) { + if (node == nullptr) return; + + if (node->left != nullptr) + parents[node->left] = node; + + if (node->right != nullptr) + parents[node->right] = node; + + mapNodesToParents(node->left, parents); + mapNodesToParents(node->right, parents); +} + +std::vector findNodesAtKDistance(TreeNode* root, TreeNode* target, int k) { + std::unordered_map parents; + mapNodesToParents(root, parents); + + std::queue q; + std::unordered_map visited; + q.push(target); + visited[target] = true; + + int level = 0; + while (!q.empty()) { + int size = q.size(); + if (level == k) { + std::vector result; + while (!q.empty()) { + result.push_back(q.front()->val); + q.pop(); + } + return result; + } + + for (int i = 0; i < size; ++i) { + TreeNode* curr = q.front(); + q.pop(); + + if (curr->left && !visited[curr->left]) { + q.push(curr->left); + visited[curr->left] = true; + } + + if (curr->right && !visited[curr->right]) { + q.push(curr->right); + visited[curr->right] = true; + } + + if (parents[curr] && !visited[parents[curr]]) { + q.push(parents[curr]); + visited[parents[curr]] = true; + } + } + ++level; + } + + return std::vector(); // If no nodes found at distance k +} + +// Function to build the binary tree based on user input +TreeNode* buildTree() { + int val; + std::cout << "Enter root value: "; + std::cin >> val; + TreeNode* root = new TreeNode(val); + + std::queue q; + q.push(root); + + while (!q.empty()) { + TreeNode* curr = q.front(); + q.pop(); + + int leftVal, rightVal; + std::cout << "Enter left child value of " << curr->val << " (or -1 if no left child): "; + std::cin >> leftVal; + if (leftVal != -1) { + curr->left = new TreeNode(leftVal); + q.push(curr->left); + } + + std::cout << "Enter right child value of " << curr->val << " (or -1 if no right child): "; + std::cin >> rightVal; + if (rightVal != -1) { + curr->right = new TreeNode(rightVal); + q.push(curr->right); + } + } + + return root; +} + +int main() { + TreeNode* root = buildTree(); + + int targetVal, k; + std::cout << "Enter target node value: "; + std::cin >> targetVal; + std::cout << "Enter distance k: "; + std::cin >> k; + + // Find the target node + TreeNode* targetNode = nullptr; + std::queue q; + q.push(root); + while (!q.empty()) { + TreeNode* curr = q.front(); + q.pop(); + if (curr->val == targetVal) { + targetNode = curr; + break; + } + if (curr->left) q.push(curr->left); + if (curr->right) q.push(curr->right); + } + + if (targetNode == nullptr) { + std::cout << "Target node not found in the tree.\n"; + return 0; + } + + std::vector nodesAtKDistance = findNodesAtKDistance(root, targetNode, k); + + // Print the nodes found at distance k from the target node + std::cout << "Nodes at distance " << k << " from target node " << targetVal << " are: "; + for (int nodeVal : nodesAtKDistance) { + std::cout << nodeVal << " "; + } + std::cout << std::endl; + + // Free allocated memory for the tree nodes to prevent memory leaks! + + return 0; +} diff --git a/December 15/C++_Surendersahk_Subsequence Sorcery.cpp b/December 15/C++_Surendersahk_Subsequence Sorcery.cpp new file mode 100644 index 0000000..e70e601 --- /dev/null +++ b/December 15/C++_Surendersahk_Subsequence Sorcery.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +int countDistinctSubsequences(const std::string& s) { + int mod = 1e9 + 7; // Modulo value for preventing integer overflow + int n = s.length(); + + std::vector dp(n + 1, 0); // Dynamic programming array + std::unordered_map last; // Store the last occurrence index of each character + + dp[0] = 1; // Empty string has one subsequence + for (int i = 1; i <= n; ++i) { + dp[i] = (2 * dp[i - 1]) % mod; // Double the count considering the addition of the new character + + // If the current character has occurred before, reduce the count by the subsequence count ending at the last occurrence of this character + if (last.find(s[i - 1]) != last.end()) { + dp[i] = (dp[i] - dp[last[s[i - 1]] - 1] + mod) % mod; + } + + last[s[i - 1]] = i; // Update the last occurrence index of the current character + } + + return static_cast(dp[n] - 1); // Exclude the count of the empty string +} + +int main() { + std::string crypticString; + std::cout << "Enter the cryptic string: "; + std::cin >> crypticString; + + int distinctSubsequences = countDistinctSubsequences(crypticString); + std::cout << "Number of distinct subsequences: " << distinctSubsequences << std::endl; + + return 0; +} diff --git a/December 16/C++_Surendersahk_Outbreak Dynamics.cpp b/December 16/C++_Surendersahk_Outbreak Dynamics.cpp new file mode 100644 index 0000000..7ee084e --- /dev/null +++ b/December 16/C++_Surendersahk_Outbreak Dynamics.cpp @@ -0,0 +1,77 @@ +#include +#include +#include + +struct Point { + int x, y; + Point(int _x, int _y) : x(_x), y(_y) {} +}; + +int minHoursToInfect(std::vector>& grid) { + int rows = grid.size(); + if (rows == 0) return -1; // Empty grid + + int cols = grid[0].size(); + std::queue zombies; + + int totalHumans = 0; // Count total humans + for (int i = 0; i < rows; ++i) { + for (int j = 0; j < cols; ++j) { + if (grid[i][j] == 1) { + zombies.push(Point(i, j)); + } else if (grid[i][j] == 0) { + ++totalHumans; + } + } + } + + if (totalHumans == 0) return 0; // No humans to infect + + int hours = 0; + std::vector> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + + while (!zombies.empty()) { + int numZombies = zombies.size(); + + for (int i = 0; i < numZombies; ++i) { + Point curr = zombies.front(); + zombies.pop(); + + for (const auto& dir : directions) { + int newX = curr.x + dir[0]; + int newY = curr.y + dir[1]; + + if (newX >= 0 && newX < rows && newY >= 0 && newY < cols && + grid[newX][newY] == 0) { // Check if the cell is a human + grid[newX][newY] = 1; // Infect the human + zombies.push(Point(newX, newY)); + --totalHumans; + } + } + } + + ++hours; + + if (totalHumans == 0) return hours; // All humans infected + } + + return -1; // Unable to infect all humans +} + +int main() { + std::vector> city = { + {0, 0, 0, 0, 1}, + {0, 1, 0, 1, -1}, + {0, 0, 0, -1, 1}, + {0, 1, 0, 0, 0} + }; + + int minHours = minHoursToInfect(city); + if (minHours == -1) { + std::cout << "It's not possible to infect all humans.\n"; + } else { + std::cout << "Minimum time to infect all humans: " << minHours << " hours.\n"; + } + + return 0; +} diff --git a/December 17/C++_Surendersahk_Bookshelf Dilemma.cpp b/December 17/C++_Surendersahk_Bookshelf Dilemma.cpp new file mode 100644 index 0000000..e15dedd --- /dev/null +++ b/December 17/C++_Surendersahk_Bookshelf Dilemma.cpp @@ -0,0 +1,93 @@ +#include +#include + +struct Node { + int data; + Node* next; + Node(int val) : data(val), next(nullptr) {} +}; + +// Function to detect and remove loops in a linked list +void detectAndRemoveLoop(Node* head) { + if (!head || !head->next) return; + + std::unordered_set visited; + Node* prev = nullptr; + Node* current = head; + + while (current) { + // If current node is already in the set, loop detected, remove the loop + if (visited.find(current) != visited.end()) { + prev->next = nullptr; // Breaking the loop + std::cout << "Loop detected and removed.\n"; + return; + } + + visited.insert(current); + prev = current; + current = current->next; + } + + std::cout << "No loop detected.\n"; +} + +// Function to display the linked list +void displayList(Node* head) { + while (head) { + std::cout << head->data << " "; + head = head->next; + } + std::cout << std::endl; +} + +// Function to create a linked list with user input values +Node* createLinkedList() { + Node* head = nullptr; + Node* tail = nullptr; + + int value; + char choice; + + do { + std::cout << "Enter value for the node: "; + std::cin >> value; + + Node* newNode = new Node(value); + + if (!head) { + head = newNode; + tail = newNode; + } else { + tail->next = newNode; + tail = newNode; + } + + std::cout << "Do you want to add another node? (y/n): "; + std::cin >> choice; + + } while (choice == 'y' || choice == 'Y'); + + return head; +} + +int main() { + std::cout << "Create a linked list...\n"; + Node* head = createLinkedList(); + + // Creating a loop for demonstration purposes + if (head) { + Node* temp = head; + while (temp->next) { + temp = temp->next; + } + // Creating a loop by connecting the last node to the second node + temp->next = head->next; + } + + detectAndRemoveLoop(head); + + std::cout << "Linked list after loop removal: "; + displayList(head); + + return 0; +} diff --git a/December 17/C++_Surendersahk_Outbreak Dynamics.cpp b/December 17/C++_Surendersahk_Outbreak Dynamics.cpp new file mode 100644 index 0000000..7ee084e --- /dev/null +++ b/December 17/C++_Surendersahk_Outbreak Dynamics.cpp @@ -0,0 +1,77 @@ +#include +#include +#include + +struct Point { + int x, y; + Point(int _x, int _y) : x(_x), y(_y) {} +}; + +int minHoursToInfect(std::vector>& grid) { + int rows = grid.size(); + if (rows == 0) return -1; // Empty grid + + int cols = grid[0].size(); + std::queue zombies; + + int totalHumans = 0; // Count total humans + for (int i = 0; i < rows; ++i) { + for (int j = 0; j < cols; ++j) { + if (grid[i][j] == 1) { + zombies.push(Point(i, j)); + } else if (grid[i][j] == 0) { + ++totalHumans; + } + } + } + + if (totalHumans == 0) return 0; // No humans to infect + + int hours = 0; + std::vector> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + + while (!zombies.empty()) { + int numZombies = zombies.size(); + + for (int i = 0; i < numZombies; ++i) { + Point curr = zombies.front(); + zombies.pop(); + + for (const auto& dir : directions) { + int newX = curr.x + dir[0]; + int newY = curr.y + dir[1]; + + if (newX >= 0 && newX < rows && newY >= 0 && newY < cols && + grid[newX][newY] == 0) { // Check if the cell is a human + grid[newX][newY] = 1; // Infect the human + zombies.push(Point(newX, newY)); + --totalHumans; + } + } + } + + ++hours; + + if (totalHumans == 0) return hours; // All humans infected + } + + return -1; // Unable to infect all humans +} + +int main() { + std::vector> city = { + {0, 0, 0, 0, 1}, + {0, 1, 0, 1, -1}, + {0, 0, 0, -1, 1}, + {0, 1, 0, 0, 0} + }; + + int minHours = minHoursToInfect(city); + if (minHours == -1) { + std::cout << "It's not possible to infect all humans.\n"; + } else { + std::cout << "Minimum time to infect all humans: " << minHours << " hours.\n"; + } + + return 0; +} diff --git a/December 18/C++_Surendersahk_ It's Christmas Season.cpp b/December 18/C++_Surendersahk_ It's Christmas Season.cpp new file mode 100644 index 0000000..1c24679 --- /dev/null +++ b/December 18/C++_Surendersahk_ It's Christmas Season.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +using namespace std; + +const int MOD = 1e9 + 7; + +// Structure for each node in the tree +struct Node { + int value; + vector children; +}; + +// Function to perform DFS traversal and count subtrees with sum divisible by X +void dfs(int node, int currSum, int X, vector& tree, vector>& dp) { + currSum = (currSum + tree[node].value) % X; + dp[node][currSum]++; + + for (int child : tree[node].children) { + dfs(child, currSum, X, tree, dp); + + // Updating counts for current node's subtree + for (auto it = dp[child].begin(); it != dp[child].end(); ++it) { + int remainder = (it->first + currSum) % X; + dp[node][remainder] = (dp[node][remainder] + it->second) % MOD; + } + } +} + +// Function to count good cuttings for each number of subtrees +vector countGoodCuttings(int N, int X, vector& values, vector>& edges) { + vector tree(N); + vector> dp(N); + + // Building the tree structure + for (int i = 0; i < N; ++i) { + tree[i].value = values[i]; + } + + for (const auto& edge : edges) { + int u = edge[0], v = edge[1]; + tree[u].children.push_back(v); + } + + // Perform DFS from the root node (index 0) + dfs(0, 0, X, tree, dp); + + // Count good cuttings for each number of subtrees + vector result(N); + for (int i = 0; i < N; ++i) { + result[i] = dp[0][i % X]; + } + + return result; +} + +int main() { + int N, X; + cout << "Enter the number of nodes: "; + cin >> N; + + cout << "Enter Alice's favorite number (X): "; + cin >> X; + + vector values(N); + cout << "Enter values assigned to each node:\n"; + for (int i = 0; i < N; ++i) { + cin >> values[i]; + } + + vector> edges(N - 1, vector(2)); + cout << "Enter edges in the tree (format: parent child):\n"; + for (int i = 0; i < N - 1; ++i) { + cin >> edges[i][0] >> edges[i][1]; + } + + vector counts = countGoodCuttings(N, X, values, edges); + + // Output the counts for each number of subtrees + for (int i = 0; i < N; ++i) { + cout << "Number of good cuttings with " << (i + 1) << " subtrees: " << counts[i] << endl; + } + + return 0; +} diff --git a/December 19/C++_Surendersahk_Symbolic Sum.cpp b/December 19/C++_Surendersahk_Symbolic Sum.cpp new file mode 100644 index 0000000..24a9ea4 --- /dev/null +++ b/December 19/C++_Surendersahk_Symbolic Sum.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; + +int symbolicSum(const string& sequence) { + stack> stk; // Pair: value, multiplier + + int multiplier = 1; + long long sum = 0; + + for (char ch : sequence) { + if (isdigit(ch)) { + sum += ch - '0'; // Accumulate the digit as part of the current sum + } else if (ch == 'X') { + stk.push({sum, multiplier}); // Push the current sum and multiplier onto the stack + sum = 0; + multiplier = 1; + } else if (ch == ' ') { + continue; // Ignore spaces + } else { // It's a multiplier + multiplier = ch - '0'; // Update the multiplier + } + } + + long long symbolicSum = 0; + + while (!stk.empty()) { + auto top = stk.top(); + stk.pop(); + + symbolicSum += top.first * top.second; // Calculate the symbolic sum + } + + return symbolicSum; +} + +int main() { + string sequence = "1 X 2 X 3 X2"; + + int result = symbolicSum(sequence); + cout << "Symbolic Sum: " << result << endl; + + return 0; +} diff --git a/December 20/C++_Surendersahk_Treasure Hunt In the isles.cpp b/December 20/C++_Surendersahk_Treasure Hunt In the isles.cpp new file mode 100644 index 0000000..2827976 --- /dev/null +++ b/December 20/C++_Surendersahk_Treasure Hunt In the isles.cpp @@ -0,0 +1,102 @@ + +#include +#include +#include +#include +using namespace std; + +const int INF = numeric_limits::max(); // Represents infinity + +// Structure to represent a cave and its attributes +struct Cave { + int cave_id; + int distance; + int interference; + + Cave(int id, int dist, int inter) : cave_id(id), distance(dist), interference(inter) {} +}; + +// Custom comparison function for the priority queue +struct Compare { + bool operator()(const Cave& a, const Cave& b) const { + if (a.distance == b.distance) { + return a.interference > b.interference; // If distances are equal, prioritize lower interference + } + return a.distance > b.distance; // Otherwise, prioritize lower distance + } +}; + +vector treasure_hunt(const vector>>& graph, int start, int end) { + int num_caves = graph.size(); + + vector distance(num_caves, INF); // Initialize distances to infinity + vector interference(num_caves, INF); // Initialize interference levels to infinity + vector parent(num_caves, -1); // Track the parent cave for constructing the path + + priority_queue, Compare> pq; + + distance[start] = 0; // Distance from start to start is 0 + interference[start] = 0; // Interference level from start to start is 0 + pq.push(Cave(start, 0, 0)); + + while (!pq.empty()) { + Cave current = pq.top(); + pq.pop(); + + int curr_cave = current.cave_id; + int curr_dist = current.distance; + + // Explore neighbors of the current cave + for (auto neighbor : graph[curr_cave]) { + int next_cave = neighbor.first; + int weight = neighbor.second; + + // Calculate the new distance and interference level + int new_dist = curr_dist + weight; + int new_interference = max(interference[curr_cave], weight); + + // Update if a shorter path with lower interference is found + if (new_dist < distance[next_cave] || (new_dist == distance[next_cave] && new_interference < interference[next_cave])) { + distance[next_cave] = new_dist; + interference[next_cave] = new_interference; + parent[next_cave] = curr_cave; + pq.push(Cave(next_cave, new_dist, new_interference)); + } + } + } + + // Reconstruct the path from end to start + vector path; + int current = end; + while (current != -1) { + path.push_back(current); + current = parent[current]; + } + reverse(path.begin(), path.end()); + + return path; +} + +int main() { + // Example graph representation (adjacency list) + vector>> graph = { + {{1, 3}, {2, 5}}, // Cave 0 + {{3, 2}}, // Cave 1 + {{3, 8}}, // Cave 2 + {} // Cave 3 (end) + }; + + int start_cave = 0; + int end_cave = 3; + + vector safest_path = treasure_hunt(graph, start_cave, end_cave); + + // Output the safest path + cout << "Safest Path: "; + for (int cave : safest_path) { + cout << cave << " "; + } + cout << endl; + + return 0; +} diff --git a/December 21/main.cpp b/December 21/main.cpp new file mode 100644 index 0000000..b6758b6 --- /dev/null +++ b/December 21/main.cpp @@ -0,0 +1,29 @@ +#include +#include +using namespace std; + +string decryptMessage(const string& encrypted, int shift) { + string decrypted = ""; + + for (char ch : encrypted) { + if (isalpha(ch)) { + char base = islower(ch) ? 'a' : 'A'; + decrypted += static_cast((ch - base - shift + 26) % 26 + base); + } else { + decrypted += ch; // Keep non-alphabetic characters unchanged + } + } + + return decrypted; +} + +int main() { + string encrypted_message = "RQHODQTLATCTQ"; + int shift = 3; // Assuming a Caesar cipher with a shift of 3 (as hinted in the message) + + string decrypted_message = decryptMessage(encrypted_message, shift); + + cout << "Decrypted Message: " << decrypted_message << endl; + + return 0; +} diff --git a/December 22/C++_Surendersahk_Rotten Oranges.cpp b/December 22/C++_Surendersahk_Rotten Oranges.cpp new file mode 100644 index 0000000..9d93d5f --- /dev/null +++ b/December 22/C++_Surendersahk_Rotten Oranges.cpp @@ -0,0 +1,80 @@ +#include +#include +#include + +using namespace std; + +int orangesRotting(vector>& grid) { + int rows = grid.size(); + int cols = grid[0].size(); + + queue> rotten; + int freshOranges = 0; + int time = 0; + + // Count fresh oranges and store rotten oranges in the queue + for (int i = 0; i < rows; ++i) { + for (int j = 0; j < cols; ++j) { + if (grid[i][j] == 1) { + ++freshOranges; + } else if (grid[i][j] == 2) { + rotten.push({i, j}); + } + } + } + + vector> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + + while (!rotten.empty() && freshOranges > 0) { + int size = rotten.size(); + for (int i = 0; i < size; ++i) { + int x = rotten.front().first; + int y = rotten.front().second; + rotten.pop(); + + for (const auto& dir : directions) { + int newX = x + dir.first; + int newY = y + dir.second; + + if (newX >= 0 && newX < rows && newY >= 0 && newY < cols && + grid[newX][newY] == 1) { + grid[newX][newY] = 2; + rotten.push({newX, newY}); + --freshOranges; + } + } + } + if (!rotten.empty()) { + ++time; + } + } + + return (freshOranges == 0) ? time : -1; +} + +int main() { + int n, m; + cout << "Enter the number of rows in the grid: "; + cin >> n; + cout << "Enter the number of columns in the grid: "; + cin >> m; + + vector> grid(n, vector(m)); + + cout << "Enter values for the grid (0 for empty, 1 for fresh oranges, 2 for rotten oranges):" << endl; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + cin >> grid[i][j]; + } + } + + int earliestTime = orangesRotting(grid); + + if (earliestTime == -1) { + cout << "All oranges cannot be rotten."; + } else { + cout << "Earliest time after which all oranges are rotten: " << earliestTime; + } + + return 0; +} diff --git a/December 23/C++_Surendersahk_Dominoes.cpp b/December 23/C++_Surendersahk_Dominoes.cpp new file mode 100644 index 0000000..a8760c7 --- /dev/null +++ b/December 23/C++_Surendersahk_Dominoes.cpp @@ -0,0 +1,50 @@ +#include +#include + +using namespace std; + +int minTimeToMakeSumsEven(vector>& dominoes) { + int oddUpper = 0, oddLower = 0; + int n = dominoes.size(); + + // Counting the number of dominoes with odd upper and lower halves + for (int i = 0; i < n; ++i) { + if (dominoes[i].first % 2 != 0) { + ++oddUpper; + } + if (dominoes[i].second % 2 != 0) { + ++oddLower; + } + } + + // If the total count of odd upper halves and odd lower halves are both even or both odd, return the count + if ((oddUpper % 2 == 0 && oddLower % 2 == 0) || (oddUpper % 2 != 0 && oddLower % 2 != 0)) { + return oddUpper % 2 == 0 ? 0 : -1; // Return 0 if they are already even or -1 if both are odd + } + + // Otherwise, return -1 as it's impossible to make the sums even + return -1; +} + +int main() { + int n; + cout << "Enter the number of domino pieces: "; + cin >> n; + + vector> dominoes(n); + + cout << "Enter the numbers on the upper and lower halves of each domino:" << endl; + for (int i = 0; i < n; ++i) { + cin >> dominoes[i].first >> dominoes[i].second; + } + + int minTime = minTimeToMakeSumsEven(dominoes); + + if (minTime == -1) { + cout << "It's impossible to make the sums even." << endl; + } else { + cout << "Minimum time required to make the sums even: " << minTime << " seconds." << endl; + } + + return 0; +} diff --git a/December 24/C++_Surendersahk_Golden Rule Violation.cpp b/December 24/C++_Surendersahk_Golden Rule Violation.cpp new file mode 100644 index 0000000..84c000d --- /dev/null +++ b/December 24/C++_Surendersahk_Golden Rule Violation.cpp @@ -0,0 +1,69 @@ +#include +#include + +using namespace std; + +int merge(vector& arr, int left, int mid, int right) { + int inversions = 0; + vector temp(right - left + 1); + int i = left, j = mid + 1, k = 0; + + while (i <= mid && j <= right) { + if (arr[i] <= arr[j]) { + temp[k++] = arr[i++]; + } else { + temp[k++] = arr[j++]; + inversions += (mid - i + 1); // Counting inversions + } + } + + while (i <= mid) { + temp[k++] = arr[i++]; + } + + while (j <= right) { + temp[k++] = arr[j++]; + } + + for (int idx = left, t = 0; idx <= right; ++idx, ++t) { + arr[idx] = temp[t]; + } + + return inversions; +} + +int mergeSort(vector& arr, int left, int right) { + int invCount = 0; + if (left < right) { + int mid = left + (right - left) / 2; + + invCount += mergeSort(arr, left, mid); + invCount += mergeSort(arr, mid + 1, right); + + invCount += merge(arr, left, mid, right); + } + return invCount; +} + +int countViolations(vector& nums) { + return mergeSort(nums, 0, nums.size() - 1); +} + +int main() { + int n; + cout << "Enter the number of integers in the set: "; + cin >> n; + + vector nums(n); + + cout << "Enter the integers in the set:" << endl; + for (int i = 0; i < n; ++i) { + cin >> nums[i]; + } + + int violations = countViolations(nums); + + cout << "Total number of violations: " << violations << endl; + + return 0; +} diff --git a/December 25/C++_Surendersahk_Harmony Hurdle.cpp b/December 25/C++_Surendersahk_Harmony Hurdle.cpp new file mode 100644 index 0000000..3d76d9a --- /dev/null +++ b/December 25/C++_Surendersahk_Harmony Hurdle.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +using namespace std; + +// Function to calculate the minimum time needed to complete all tasks +int minTime(vector>& dependencies, vector& taskTimes) { + int n = taskTimes.size(); + vector inDegree(n, 0); + vector totalTime(n, 0); + queue q; + + // Calculate in-degrees for each task + for (int i = 0; i < n; ++i) { + for (int j : dependencies[i]) { + ++inDegree[i]; + } + } + + // Initialize queue with tasks having zero in-degree + for (int i = 0; i < n; ++i) { + if (inDegree[i] == 0) { + q.push(i); + totalTime[i] = taskTimes[i]; + } + } + + // Perform topological sorting and calculate minimum time + int minExecutionTime = 0; + while (!q.empty()) { + int current = q.front(); + q.pop(); + + for (int dependency : dependencies[current]) { + totalTime[dependency] = max(totalTime[dependency], totalTime[current] + taskTimes[dependency]); + --inDegree[dependency]; + + if (inDegree[dependency] == 0) { + q.push(dependency); + } + } + + minExecutionTime = max(minExecutionTime, totalTime[current]); + } + + return minExecutionTime; +} + +int main() { + int n; + cout << "Enter the number of tasks: "; + cin >> n; + + vector taskTimes(n); + vector> dependencies(n); + + cout << "Enter the time required for each task:" << endl; + for (int i = 0; i < n; ++i) { + cin >> taskTimes[i]; + } + + cout << "Enter dependencies for each task (enter -1 to end input for a task):" << endl; + for (int i = 0; i < n; ++i) { + int dep; + while (true) { + cin >> dep; + if (dep == -1) { + break; + } + dependencies[i].push_back(dep); + } + } + + int minExecutionTime = minTime(dependencies, taskTimes); + cout << "Minimum time needed to complete all tasks: " << minExecutionTime << " units." << endl; + + return 0; +} diff --git a/December 26/C++_Surendersahk_The Phantom Cycle.cpp b/December 26/C++_Surendersahk_The Phantom Cycle.cpp new file mode 100644 index 0000000..21043fc --- /dev/null +++ b/December 26/C++_Surendersahk_The Phantom Cycle.cpp @@ -0,0 +1,94 @@ +#include + +using namespace std; + +struct Node { + int data; + Node* next; +}; + +// Function to detect a cycle in a linked list +bool hasCycle(Node* head) { + if (head == nullptr || head->next == nullptr) { + return false; + } + + Node* slow = head; + Node* fast = head->next; + + while (fast != nullptr && fast->next != nullptr) { + if (slow == fast) { + return true; // Cycle detected + } + + slow = slow->next; + fast = fast->next->next; + } + + return false; // No cycle found +} + +// Function to create a new node in the linked list +Node* createNode(int data) { + Node* newNode = new Node(); + newNode->data = data; + newNode->next = nullptr; + return newNode; +} + +// Function to add a new node to the linked list +void addNode(Node* &head, int data) { + if (head == nullptr) { + head = createNode(data); + return; + } + + Node* temp = head; + while (temp->next != nullptr) { + temp = temp->next; + } + + temp->next = createNode(data); +} + +// Function to display the linked list +void displayList(Node* head) { + Node* temp = head; + while (temp != nullptr) { + cout << temp->data << " "; + temp = temp->next; + } + cout << endl; +} + +int main() { + Node* head = nullptr; + int n; + cout << "Enter the number of elements in the linked list: "; + cin >> n; + + cout << "Enter the elements of the linked list: "; + for (int i = 0; i < n; ++i) { + int data; + cin >> data; + addNode(head, data); + } + + // Creating a cycle for demonstration purposes (comment out for a non-cyclic list) + Node* temp = head; + while (temp->next != nullptr) { + temp = temp->next; + } + temp->next = head; // Creating a cycle + + cout << "Linked list: "; + displayList(head); + + if (hasCycle(head)) { + cout << "The linked list contains a cycle." << endl; + } else { + cout << "The linked list does not contain a cycle." << endl; + } + + return 0; +} diff --git a/December 27/C++_Surendersahk_Circle of Endurance.cpp b/December 27/C++_Surendersahk_Circle of Endurance.cpp new file mode 100644 index 0000000..5e645dd --- /dev/null +++ b/December 27/C++_Surendersahk_Circle of Endurance.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace std; + +// Function to find the starting point to complete the circular route +int findStartingPoint(vector& petrol, vector& distance) { + int n = petrol.size(); + int start = 0, currPetrol = 0, totalPetrol = 0; + + for (int i = 0; i < n; ++i) { + totalPetrol += petrol[i] - distance[i]; + currPetrol += petrol[i] - distance[i]; + + if (currPetrol < 0) { + currPetrol = 0; + start = i + 1; // Update the potential starting point + } + } + + return (totalPetrol >= 0) ? start : -1; // If the total petrol is enough to complete the circle, return the starting point +} + +int main() { + int n; + cout << "Enter the number of petrol pumps: "; + cin >> n; + + vector petrol(n); + vector distance(n); + + cout << "Enter the petrol reserves at each petrol pump:" << endl; + for (int i = 0; i < n; ++i) { + cin >> petrol[i]; + } + + cout << "Enter the distance to the next petrol pump from each pump:" << endl; + for (int i = 0; i < n; ++i) { + cin >> distance[i]; + } + + int start = findStartingPoint(petrol, distance); + + if (start == -1) { + cout << "It's impossible to complete the circular route without running out of fuel." << endl; + } else { + cout << "Start at petrol pump " << start + 1 << " to complete the circular route without running out of fuel." << endl; + } + + return 0; +} diff --git a/December 28/C++_Surendersahk_The Selling Game.cpp b/December 28/C++_Surendersahk_The Selling Game.cpp new file mode 100644 index 0000000..fdeeb6aad9 --- /dev/null +++ b/December 28/C++_Surendersahk_The Selling Game.cpp @@ -0,0 +1,65 @@ +#include +#include +#include + +using namespace std; + +struct Gadget { + int performanceLevel; + int minPrice; +}; + +int maxGadgetsSold(int x, vector& gadgets, int z, vector>& clients) { + int soldCount = 0; + vector sold(x, false); + + // Sort gadgets based on performance level in non-decreasing order + sort(gadgets.begin(), gadgets.end(), [](const Gadget& a, const Gadget& b) { + return a.performanceLevel < b.performanceLevel; + }); + + // Sort clients based on their performance level requirement in non-increasing order + sort(clients.begin(), clients.end(), greater>()); + + for (auto& client : clients) { + int requiredPerformance = client.first; + int maxPrice = client.second; + + for (int i = 0; i < x; ++i) { + if (!sold[i] && gadgets[i].performanceLevel > requiredPerformance && gadgets[i].minPrice <= maxPrice) { + sold[i] = true; + ++soldCount; + break; // Move to the next client + } + } + } + + return soldCount; +} + +int main() { + int x; // Number of unsold items + cout << "Enter the number of unsold items: "; + cin >> x; + + vector gadgets(x); + cout << "Enter performance level and minimum price for each item:" << endl; + for (int i = 0; i < x; ++i) { + cin >> gadgets[i].performanceLevel >> gadgets[i].minPrice; + } + + int z; // Number of interested clients + cout << "Enter the number of interested clients: "; + cin >> z; + + vector> clients(z); + cout << "Enter performance level requirement and maximum price for each client:" << endl; + for (int i = 0; i < z; ++i) { + cin >> clients[i].first >> clients[i].second; + } + + int maxSold = maxGadgetsSold(x, gadgets, z, clients); + cout << "Maximum number of gadgets that can be sold: " << maxSold << endl; + + return 0; +} diff --git a/December 29/C++_Surendersahk_ Cartesian Walk Validator.cpp b/December 29/C++_Surendersahk_ Cartesian Walk Validator.cpp new file mode 100644 index 0000000..d6d5e0e --- /dev/null +++ b/December 29/C++_Surendersahk_ Cartesian Walk Validator.cpp @@ -0,0 +1,48 @@ +#include +#include + +using namespace std; + +bool isValidWalk(vector& directions) { + if (directions.size() != 10) { + return false; // If the walk is not exactly 10 minutes long + } + + int x = 0, y = 0; // Starting point coordinates + + for (const string& dir : directions) { + if (dir == "n") { + ++y; + } else if (dir == "s") { + --y; + } else if (dir == "e") { + ++x; + } else if (dir == "w") { + --x; + } + } + + // Return true if the walk ends at the starting point (0, 0) + return (x == 0 && y == 0); +} + +int main() { + vector directions; + char direction; + + cout << "Enter the directions for the walk (n/s/e/w):" << endl; + for (int i = 0; i < 10; ++i) { + cin >> direction; + directions.push_back(string(1, direction)); + } + + bool isValid = isValidWalk(directions); + + if (isValid) { + cout << "The walk will take exactly ten minutes and return you to your starting point." << endl; + } else { + cout << "The walk will not take exactly ten minutes or won't return you to your starting point." << endl; + } + + return 0; +} diff --git a/December 30/C++_Surendersahk_ Tree Inversions.cpp b/December 30/C++_Surendersahk_ Tree Inversions.cpp new file mode 100644 index 0000000..0b72cd4 --- /dev/null +++ b/December 30/C++_Surendersahk_ Tree Inversions.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +using namespace std; + +const int MAXN = 100005; // Maximum number of nodes + +vector tree[MAXN]; +int color[MAXN]; + +vector eulerTour; // Euler tour of the tree +vector firstOccur(MAXN, -1); // First occurrence of a node in euler tour +vector idxInEuler; // Index of a node in euler tour + +// Function to perform Euler tour of the tree +void dfs(int node, int parent) { + eulerTour.push_back(color[node]); + idxInEuler.push_back(node); + + if (firstOccur[node] == -1) { + firstOccur[node] = eulerTour.size() - 1; + } + + for (int child : tree[node]) { + if (child != parent) { + dfs(child, node); + eulerTour.push_back(color[node]); + idxInEuler.push_back(node); + } + } +} + +// Function to count inversions in an array +int countInversions(vector& arr) { + int inversions = 0; + map freq; + + for (int i = arr.size() - 1; i >= 0; --i) { + inversions += freq.upper_bound(arr[i])->second; + freq[arr[i]]++; + } + + return inversions; +} + +int main() { + int N, Q; + cin >> N; // Number of nodes in the tree + + // Input colors of nodes + for (int i = 1; i <= N; ++i) { + cin >> color[i]; + } + + // Input the tree edges + for (int i = 1; i <= N - 1; ++i) { + int u, v; + cin >> u >> v; + tree[u].push_back(v); + tree[v].push_back(u); + } + + dfs(1, -1); // Perform Euler tour starting from root node (node 1) + + // Process queries + cin >> Q; + for (int q = 0; q < Q; ++q) { + int x, y; + cin >> x >> y; + + int lcaIndex = min(firstOccur[x], firstOccur[y]); + int rcaIndex = max(firstOccur[x], firstOccur[y]); + + vector cxy(eulerTour.begin() + lcaIndex, eulerTour.begin() + rcaIndex + 1); + + int inversionsXY = countInversions(cxy); + + cout << "Inversions between " << x << " and " << y << ": " << inversionsXY * 2 << endl; + } + + return 0; +} diff --git a/December 31/C++_Surendersahk_N Queens.cpp b/December 31/C++_Surendersahk_N Queens.cpp new file mode 100644 index 0000000..8c74125 --- /dev/null +++ b/December 31/C++_Surendersahk_N Queens.cpp @@ -0,0 +1,64 @@ +#include +#include + +using namespace std; + +bool isSafe(vector& board, int row, int col) { + for (int i = 0; i < row; ++i) { + if (board[i] == col || board[i] - i == col - row || board[i] + i == col + row) { + return false; + } + } + return true; +} + +void solveNQueens(vector>& solutions, vector& board, int row, int n) { + if (row == n) { + solutions.push_back(board); + return; + } + + for (int col = 0; col < n; ++col) { + if (isSafe(board, row, col)) { + board[row] = col; + solveNQueens(solutions, board, row + 1, n); + } + } +} + +void printSolutions(vector>& solutions) { + for (int i = 0; i < solutions.size(); ++i) { + cout << "Solution " << i + 1 << ":\n"; + for (int row = 0; row < solutions[i].size(); ++row) { + for (int col = 0; col < solutions[i].size(); ++col) { + if (solutions[i][row] == col) { + cout << "Q "; + } else { + cout << ". "; + } + } + cout << endl; + } + cout << endl; + } +} + +int main() { + int n; + cout << "Enter the value of N for the N-Queens problem: "; + cin >> n; + + vector> solutions; + vector board(n, -1); + + solveNQueens(solutions, board, 0, n); + + if (solutions.empty()) { + cout << "No solutions found for N = " << n << endl; + } else { + cout << "All possible solutions for N = " << n << ":\n"; + printSolutions(solutions); + } + + return 0; +}