allcoding1
27.7K subscribers
2.2K photos
2 videos
77 files
853 links
Download Telegram
Send Questions
👍1
allcoding1
Photo
#include <iostream>
#include <cmath>

struct Circle {
    double x; // x-coordinate of the center
    double y; // y-coordinate of the center
    double r; // radius
};

double distanceBetweenCenters(Circle A, Circle B) {
    return sqrt(pow((B.x - A.x), 2) + pow((B.y - A.y), 2));
}

int main() {
    Circle A, B;

    // Example values
    A.x = 0;
    A.y = 0;
    A.r = 5;
    B.x = 10;
    B.y = 0;
    B.r = 7;

    double distance = distanceBetweenCenters(A, B);
    double sumOfRadii = A.r + B.r;
    double differenceOfRadii = abs(A.r - B.r);

    if (distance == sumOfRadii) {
        std::cout &lt;&lt; "The circles are touching at a single point." &lt;&lt; std::endl;
    } else if (distance &lt; sumOfRadii) {
        std::cout &lt;&lt; "The circles are intersecting." &lt;&lt; std::endl;
    } else if (distance == differenceOfRadii) {
        std::cout &lt;&lt; "The circles are touching from within or without." &lt;&lt; std::endl;
    } else {
        std::cout &lt;&lt; "The circles are not intersecting." &lt;&lt; std::endl;
    }

    if ((A.x == B.x) &amp;&amp; (A.y == B.y) &amp;&amp; (A.r == B.r)) {
        std::cout &lt;&lt; "The circles are concentric." &lt;&lt; std::endl;
    }

    return 0;
}


C++

Telegram:- @allcoding1
👍1😁1
int min(string str){
unordered_map<char,int>mp;
for(char :str){
  mp[ch]++;
}
unodered_set<int>d;
for(auto it:mp){
  d.insert(it.second);
}
return d.size();

}

Music Teacher
Only 4 test cases pass

Telegram:- @allcoding1
👍1
Send ur Questions
👍1🥰1
allcoding1
Photo
#include <iostream>
#include <vector>
using namespace std;

bool isValidPermutation(const vector<int>&amp; permutation) {
    for (int i = 0; i &lt; permutation.size(); i++) {
        if (permutation[i] % (i + 1) != 0 || (i + 1) % permutation[i] != 0) {
            return false;
        }
    }
    return true;
}

void generatePermutations(vector<int>&amp; nums, int start, vector<vector<int>&gt;&amp; result) {
    if (start == nums.size()) {
        result.push_back(nums);
        return;
    }
    for (int i = start; i &lt; nums.size(); i++) {
        swap(nums[start], nums[i]);
        generatePermutations(nums, start + 1, result);
        swap(nums[start], nums[i]);
    }
}

int countValidPermutations(int N) {
    vector<int> nums(N);
    for (int i = 0; i &lt; N; i++) {
        nums[i] = i + 1;
    }
    vector<vector<int>&gt; permutations;
    generatePermutations(nums, 0, permutations);

    int count = 0;
    for (const auto&amp; perm : permutations) {
        if (isValidPermutation(perm)) {
            count++;
        }
    }
    return count;
}

int main() {
    int N = 2;
    cout &lt;&lt; "Number of valid permutations: " &lt;&lt; countValidPermutations(N) &lt;&lt; endl;
    return 0;
}



Valid permutations

Telegram:- @allcoding1
👍1
Valid permutations

Telegram:- @allcoding1
👍1
allcoding1
Photo
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>

struct Client {
std::string name;
double total_invested_in_bonds;
double total_invested_in_stocks;
};

bool compareByBonds(const Client &amp;a, const Client &amp;b) {
return a.total_invested_in_bonds &gt; b.total_invested_in_bonds;
}

int main() {
std::vector<client> clients = {
{"Client1", 7500.0, 3000.0},
{"Client2", 6000.0, 5000.0},
{"Client3", 4000.0, 6000.0},
// Add more clients as needed
};

// Sort clients based on total_invested_in_bonds in descending order
std::sort(clients.begin(), clients.end(), compareByBonds);

// Display the result
std::cout &lt;&lt; std::left &lt;&lt; std::setw(15) &lt;&lt; "Client Name"
&lt;&lt; std::setw(25) &lt;&lt; "Total Invested in Bonds"
&lt;&lt; "Total Invested in Stocks" &lt;&lt; std::endl;

for (const auto &amp;client : clients) {
if (client.total_invested_in_bonds &gt; 5000.00) {
std::cout &lt;&lt; std::left &lt;&lt; std::setw(15) &lt;&lt; client.name
&lt;&lt; std::fixed &lt;&lt; std::setprecision(2)
&lt;&lt; std::setw(25) &lt;&lt; client.total_invested_in_bonds
&lt;&lt; client.total_invested_in_stocks &lt;&lt; std::endl;
}
}

return 0;
}
You can modify the clients vector to include more clients with their respective investments in bonds and stocks. When you run this program, it will display the result according to the specified requirements.</client></algorithm></vector></iomanip></string></iostream>

Telegram:- @allcoding1
allcoding1
Photo
#include <iostream>
#include <sql.h>
#include <sqlext.h>

#define MAX_QUERY_LEN 1000

int main() {
// Declare variables for ODBC connection
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;

// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;henv);

// Set the ODBC version to use
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);

// Allocate connection handle
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &amp;hdbc);

// Connect to the data source
retcode = SQLConnect(hdbc, (SQLCHAR*)"your_datasource", SQL_NTS, (SQLCHAR*)"username", SQL_NTS, (SQLCHAR*)"password", SQL_NTS);

// Allocate statement handle
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &amp;hstmt);

// Prepare the SQL query
char query[MAX_QUERY_LEN] = "SELECT DATE_FORMAT(date_column, '%Y-%m') AS month_year, source, COUNT(*) AS total_number FROM your_table WHERE YEAR(date_column) = '2022' AND (source = 'Jobs' OR source = 'Freelancers') GROUP BY month_year, source ORDER BY month_year ASC, source ASC";

// Execute the SQL query
retcode = SQLExecDirect(hstmt, (SQLCHAR*)query, SQL_NTS);

// Fetch and process the results
while (SQLFetch(hstmt) == SQL_SUCCESS) {
// Process the retrieved data here
}

// Free the handles
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);

return 0;
}
Please note that the above code provides a basic framework for executing SQL queries in C++. You will need to replace your_datasource, username, password, your_table, and date_column with your actual database connection details, table name, and column name.

Telegram:- @allcoding1
👍4
int solve(int n, vector<int>& arr) {
    while (arr.size() > 1) {
        int len = INT_MAX;
        int idx = -1;
        for (int i = 0; i < arr.size() - 1; ++i) {
            int d = arr[i + 1];
            if (d == 0 || arr[i] == 0) {
                continue;
            }
            int r = min(arr[i] % d, d % arr[i]);
            if (r < len) {
                len = r;
                idx = i;
            }
        }
        if (idx == -1) {
            break;
        }
        int d = arr[idx + 1];
        if (d != 0) {
            arr[idx] = min(arr[idx] % d, d % arr[idx]);
        }
        arr.erase(arr.begin() + idx + 1);
    }
    return arr.size();
}

Women Day Mathematics Challenge

Telegram:- @allcoding1
👍1
Telegram:- @allcoding1
URL Hashing

Telegram:- @allcoding1