diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..865ba8bb --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:\\msys64\\ucrt64\\bin\\gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/Array/Rotate_array_90degree.cpp b/Array/Rotate_array_90degree.cpp new file mode 100644 index 00000000..2c3e2215 --- /dev/null +++ b/Array/Rotate_array_90degree.cpp @@ -0,0 +1,71 @@ + +#include +#include +using namespace std; + +void rotateMatrix(vector> &matrix) +{ + int rows = matrix.size(); + int cols = matrix[0].size(); + + // Create a new matrix to store rotated values + vector> rotated(cols, vector(rows)); + + // Rotate the matrix (90 degrees clockwise) + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + rotated[j][rows - 1 - i] = matrix[i][j]; + } + } + + // Copy rotated matrix back to original matrix + matrix = rotated; +} + +int main() +{ + int rows, cols; + cout << "Enter number of rows: "; + cin >> rows; + cout << "Enter number of columns: "; + cin >> cols; + + vector> matrix(rows, vector(cols)); + + // Input matrix elements + cout << "Enter matrix elements:\n"; + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + cin >> matrix[i][j]; + } + } + + cout << "\nOriginal Matrix:\n"; + for (const auto &row : matrix) + { + for (int val : row) + { + cout << val << " "; + } + cout << endl; + } + + // Rotate the matrix + rotateMatrix(matrix); + + cout << "\nRotated Matrix (90 degrees clockwise):\n"; + for (const auto &row : matrix) + { + for (int val : row) + { + cout << val << " "; + } + cout << endl; + } + + return 0; +} diff --git a/Bitmasking/.vscode/tasks.json b/Bitmasking/.vscode/tasks.json new file mode 100644 index 00000000..865ba8bb --- /dev/null +++ b/Bitmasking/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:\\msys64\\ucrt64\\bin\\gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/Bitmasking/maximum_xor_2numbers.cpp b/Bitmasking/maximum_xor_2numbers.cpp new file mode 100644 index 00000000..edaa26ee --- /dev/null +++ b/Bitmasking/maximum_xor_2numbers.cpp @@ -0,0 +1,21 @@ +// C++ program to find the maximum +// XOR value of two elements in an array +#include +using namespace std; + +// Function to find the maximum XOR +int maxXOR(vector &arr) { + int res = 0; + for (int i = 0; i < arr.size(); i++) { + for (int j = i + 1; j < arr.size(); j++) { + res = max(res, arr[i] ^ arr[j]); + } + } + return res; +} + +int main() { + vector arr = {25, 10, 2, 8, 5, 3}; + cout << maxXOR(arr); + return 0; +}