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 << "The circles are touching at a single point." << std::endl;
} else if (distance < sumOfRadii) {
std::cout << "The circles are intersecting." << std::endl;
} else if (distance == differenceOfRadii) {
std::cout << "The circles are touching from within or without." << std::endl;
} else {
std::cout << "The circles are not intersecting." << std::endl;
}
if ((A.x == B.x) && (A.y == B.y) && (A.r == B.r)) {
std::cout << "The circles are concentric." << std::endl;
}
return 0;
}
C++
Telegram:- @allcoding1
#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 << "The circles are touching at a single point." << std::endl;
} else if (distance < sumOfRadii) {
std::cout << "The circles are intersecting." << std::endl;
} else if (distance == differenceOfRadii) {
std::cout << "The circles are touching from within or without." << std::endl;
} else {
std::cout << "The circles are not intersecting." << std::endl;
}
if ((A.x == B.x) && (A.y == B.y) && (A.r == B.r)) {
std::cout << "The circles are concentric." << 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
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
allcoding1
Photo
#include <iostream>
#include <vector>
using namespace std;
bool isValidPermutation(const vector<int>& permutation) {
for (int i = 0; i < permutation.size(); i++) {
if (permutation[i] % (i + 1) != 0 || (i + 1) % permutation[i] != 0) {
return false;
}
}
return true;
}
void generatePermutations(vector<int>& nums, int start, vector<vector<int>>& result) {
if (start == nums.size()) {
result.push_back(nums);
return;
}
for (int i = start; i < 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 < N; i++) {
nums[i] = i + 1;
}
vector<vector<int>> permutations;
generatePermutations(nums, 0, permutations);
int count = 0;
for (const auto& perm : permutations) {
if (isValidPermutation(perm)) {
count++;
}
}
return count;
}
int main() {
int N = 2;
cout << "Number of valid permutations: " << countValidPermutations(N) << endl;
return 0;
}
Valid permutations
Telegram:- @allcoding1
👍1
allcoding1
Photo
#include <iostream>You can modify the
#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 &a, const Client &b) {
return a.total_invested_in_bonds > 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 << std::left << std::setw(15) << "Client Name"
<< std::setw(25) << "Total Invested in Bonds"
<< "Total Invested in Stocks" << std::endl;
for (const auto &client : clients) {
if (client.total_invested_in_bonds > 5000.00) {
std::cout << std::left << std::setw(15) << client.name
<< std::fixed << std::setprecision(2)
<< std::setw(25) << client.total_invested_in_bonds
<< client.total_invested_in_stocks << std::endl;
}
}
return 0;
}
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