Example 1: c++ to python converter online
using namespace std;
int main()
{
int z,a[3],b[3],al=0,bo=0;
for(int i=0;i<3;i++)
cin>>a[i];
for(int i=0;i<3;i++)
cin>>b[i];
for(int i=0;i<3;i++)
{
if(a[i]==b[i])
{z++;}
else
if(a[i]>b[i])
al++;
else
bo++;
}
cout<<al<<" "<<bo;
return 0;
}using namespace std;
// Function to convert Indian Numeric
// System to International Numeric System
string convert(string input)
{
// Length of the input string
int len = input.length();
// Removing all the separators(, )
// From the input string
for (int i = 0; i < len; i++) {
if (input[i] == ',') {
input.erase(input.begin() + i);
len--;
i--;
}
}
// Initialize output string
string output = "";
int ctr = 0;
// Process the input string
for (int i = len - 1; i >= 0; i--) {
ctr++;
output = input[i] + output;
// Add a separator(, ) after
// every third digit
if (ctr % 3 == 0 && ctr < len) {
output = ',' + output;
}
}
// Return the output string back
// to the main function
return output;
}
// Driver Code
int main()
{
string input1 = "12,34,56,789";
string input2 = "90,05,00,00,000";
cout << convert(input1) << endl;
cout << convert(input2) << endl;
}
Example 2: c++ to python converter online
import torch
import torch.nn as nn
import torch.nn.functional as F
class BidirectionalLSTM(nn.Module):
def __init__(self, n_in, n_hidden, n_out):
super(BidirectionalLSTM, self).__init__()
self.rnn = nn.LSTM(n_in, n_hidden, bidirectional=True)
self.embedding = nn.Linear(n_hidden * 2, n_out)
def forward(self, input):
recurrent, _ = self.rnn(input)
T, b, h = recurrent.size()
t_rec = recurrent.view(T * b, h)
output = self.embedding(t_rec)
output = output.view(T, b, -1)
return output
Example 3: c++ to python converter online
import torch
import torch.nn as nn
import torch.nn.functional as F
class BidirectionalLSTM(nn.Module):
def __init__(self, n_in, n_hidden, n_out):
super(BidirectionalLSTM, self).__init__()
self.rnn = nn.LSTM(n_in, n_hidden, bidirectional=True)
self.embedding = nn.Linear(n_hidden * 2, n_out)
def forward(self, input):
recurrent, _ = self.rnn(input)
T, b, h = recurrent.size()
t_rec = recurrent.view(T * b, h)
output = self.embedding(t_rec)
output = output.view(T, b, -1)
return output
Example 4: c++ code to python code converter online
using namespace std;
int main()
{
char gender;
double bodyweight, wrist, waist, hip, forearm, B, bodyfat, bfPercentage, A1, A2, A3, A4, A5;
bodyfat = bodyweight - B;
bfPercentage = (bodyfat * 100) / bodyweight;
cout << "Input gender (m/f): ";
cin >> gender;
switch (gender)
{
case 'F':
case 'f':
cout << "Enter body weight: ";
cin >> bodyweight;
cout << "Enter wrist measurement (at fullest point): ";
cin >> wrist;
cout << "Enter waist measurement (at navel): ";
cin >> waist;
cout << "Enter hip measurement (at fullest point): ";
cin >> hip;
cout << "Enter forearm measurement (at fullest point): ";
cin >> forearm;
A1 = (bodyweight * 0.723) + 8.987;
A2 = (wrist) / 3.140;
A3 = (waist) * 0.157;
A4 = (hip) * 0.249;
A5 = (forearm) * 0.434;
B = A1 + A2 - A3 - A4 + A5;
cout << "Your body fat is: " << bodyfat << endl
<< "Body fat percentage: " << bfPercentage << "%";
break;
case 'M':
case 'm':
cout << "Enter body weight: ";
cin >> bodyweight;
cout << "Enter wrist measurement (at fullest point): ";
cin >> wrist;
A1 = (bodyweight * 1.082) + 94.42;
A2 = wrist * 4.14;
B = A1 - A2;
cout << "Your body fat is: " << bodyfat << endl
<< "Body fat percentage: " << bfPercentage << "%";
break;
default:
cout << "Invalid gender.";
}
return 0;
}