allcoding1_official
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 &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;
}
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_official
#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;
}
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_official
👍2
allcoding1_official
Photo
#include <iostream>Please note that the above code provides a basic framework for executing SQL queries in C++. You will need to replace
#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, &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, &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, &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;
}
your_datasource
, username
, password
, your_table
, and date_column
with your actual database connection details, table name, and column name.Telegram:- @allcoding1_official
👍4
allcoding1_official
Photo
#define vv(a) vector<vector<int>>(a)
int solve(int n, int m, vector<vector<int>> &a)
{
vv(right)(n, vector<int>(m, 0));
vv(down)(n, vector<int>(m, 0));
vv(left)(n, vector<int>(m, 0));
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = m - 1; j >= 0; j--)
{
right[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
{
left[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}
for (int j = 0; j < m; j++)
{
int cnt = 0;
for (int i = n - 1; i >= 0; i--)
{
down[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (a[i][j] == 1)
{
ans += (right[i][j] * down[i][j]);
ans += (left[i][j] * down[i][j]);
}
}
}
return ans;
}
C++
Telegram:- @allcoding1_official
int solve(int n, int m, vector<vector<int>> &a)
{
vv(right)(n, vector<int>(m, 0));
vv(down)(n, vector<int>(m, 0));
vv(left)(n, vector<int>(m, 0));
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = m - 1; j >= 0; j--)
{
right[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
{
left[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}
for (int j = 0; j < m; j++)
{
int cnt = 0;
for (int i = n - 1; i >= 0; i--)
{
down[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (a[i][j] == 1)
{
ans += (right[i][j] * down[i][j]);
ans += (left[i][j] * down[i][j]);
}
}
}
return ans;
}
C++
Telegram:- @allcoding1_official
👍4❤1❤🔥1👎1
struct Request {
string id;
string start_time;
string end_time;
};
bool compare(Request a, Request b) {
return a.start_time < b.start_time;
}
int solve(vector<Request> requests) {
sort(requests.begin(), requests.end(), compare);
int max_concurrent = 0;
int current_concurrent = 0;
string current_end_time = "00:00:00";
for (Request request : requests) {
if (request.start_time >= current_end_time) {
current_concurrent--;
} else {
current_concurrent++;
if (current_concurrent > max_concurrent) {
max_concurrent = current_concurrent;
}
}
if (request.end_time > current_end_time) {
current_end_time = request.end_time;
}
}
return max_concurrent;
}
@allcoding1_official
string id;
string start_time;
string end_time;
};
bool compare(Request a, Request b) {
return a.start_time < b.start_time;
}
int solve(vector<Request> requests) {
sort(requests.begin(), requests.end(), compare);
int max_concurrent = 0;
int current_concurrent = 0;
string current_end_time = "00:00:00";
for (Request request : requests) {
if (request.start_time >= current_end_time) {
current_concurrent--;
} else {
current_concurrent++;
if (current_concurrent > max_concurrent) {
max_concurrent = current_concurrent;
}
}
if (request.end_time > current_end_time) {
current_end_time = request.end_time;
}
}
return max_concurrent;
}
@allcoding1_official
👍2