#include <iostream>

using namespace std;

int main()
{
int n;
cin>>n;

int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}

for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(arr[j]<arr[i]){
int temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}

for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}cout<<endl;

return 0;

}
char a = 'a';
int ia = (int)a;
/* note that the int cast is not necessary -- int ia = a would suffice */
void insertionsort(int A[], int size){
int i, j;
for(i=1; i<size; i++){
key= A[i];
j=i-1;

while(j>=0 && A[j]> key){
A[j+1]= A[j];
j=j-1;
}
A[j+1]= key;
}
}
#include<bits/stdc++.c>

int binarysearch(int arr[], int l, int r, int x){
if(r>=l){
int mid= l+(r-1)/2;
if(arr[mid]== x){
return mid;
}
if(x<arr[mid]){
return binarysearch(arr, l ,mid-1, x);
}
if(x>arr[mid]){
return binarysearch(arr, mid+1, r, x);
}
}
return -1;

}

int main(){
int arr[]= {10, 20, 30, 40, 50};
int x= 30;
int n= sizeof(arr)/ sizeof(arr);
int result= binarysearch(arr, 0, 1, n-1m, x);
(result==-1)? cout<<"Element is not present" : cout<<"Element is present at"<<result;
return 0;

}
#include <string>
using namespace std;
std::string even_or_odd(int number)
{
string EvenOrOdd;
if (number %2 == 0){
EvenOrOdd = "Even";
}else{
EvenOrOdd = "Odd";
}
return EvenOrOdd;
}
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
int d;
long ld;
char ch;
float f;
double lf;

scanf("%d %ld %c %f %lf",&d,&ld,&ch,&f,&lf);
printf("%d\n%ld\n%c\n%f\n%lf",d,ld,ch,f,lf);
return 0;
}
#include <stdio.h>

void update(int *a,int *b) {

int ans = *a;
*a = *a + *b;
*b = ans - *b;
if (*b <0){
*b = -(*b);
}

//printf("*pb %d\n", *pb);
//printf("*a %d\n",*a);
//printf("*b %d\n",*b);
//printf("*pa %d\n",*pa);
//printf("\n");
//
}

int main() {
int a, b;
int *pa = &a, *pb = &b;

scanf("%d %d", &a, &b);
update(pa, pb);
printf("%d\n%d", a, b);

return 0;
}
// Online C++ compiler to run C++ program online
#include <iostream>
//#include <cstdio>
//#include <vector>
//#include <iostream>
//#include <algorithm>
#include <list> // for arra list list<foodIdeams>....
using namespace std;

class Maths {
public:
int oneQty;
int twoQty;
int sumTotal;

int width;
int height;
int length;
int areaTotal;
Maths(int Width, int Height, int Length, int OneQty, int TwoQty){
width = Width;
height = Height;
length = Length;
oneQty = OneQty;
twoQty = TwoQty;
}
int MakeArea(int width, int height, int length) {
areaTotal = width * height * length;
return areaTotal;
}
void printArea() {
cout << "Wigth: " << width << endl;
cout << "Height: " << height << endl;
cout << "length: " << length << endl;
cout << "" << endl;
cout << "Total: "<< areaTotal << endl;
}
int subtraction(int oneQty, int twoQty) {
sumTotal = oneQty - twoQty;
return sumTotal;
}
void printSum() {
cout << "First Qty: " << oneQty << endl;
cout << "Second Qty: " << twoQty << endl;
cout << "" << endl;
cout << "Subtarction Totle: " << sumTotal << endl;
}

};

int main() {
Maths One(4, 10, 13,3,4);
One.MakeArea(3,1,1);
One.subtraction(10, 7);
One.printArea();

One.printSum();

return 0;
}
#include <iostream>
//#include <cstdio>
//#include <vector>
//#include <iostream>
//#include <algorithm>
#include <list> // for arra list list<foodIdeams>....
//using namespace std;
//std:: not using namespace exsample
namespace Happy {
int num = 32;
std::string name = "Jarod";

}
int num = 42;
std::string name = "Sid";
}
int main() {
std::cout << Happy::name << std::endl;
std::cout << Happy::num << std::endl;
std::cout << "" << std::endl;
return 0;
}
// Online C++ compiler to run C++ program online
#include <iostream>
//#include <cstdio>
//#include <vector>
//#include <iostream>
//#include <algorithm>
#include <list> // for arra list list<foodIdeams>....
using namespace std;

class foodList{
public:
string recipe;
list<string> ingredient;

foodList(string Recipe){
recipe = Recipe;
}

void listMaker(){
cout << "Recipe Name: "<< recipe << endl;
cout << "" << endl;
cout << "Ingredients: " << endl;
for (string e : ingredient){
cout << e << endl;
}
}
};

int main() {

foodList recipe1("spaghetti");
recipe1.ingredient.push_back("1 pound lean ground meat like beef, turkey, chicken or lamb");
recipe1.ingredient.push_back("3 tablespoons olive oil");
recipe1.ingredient.push_back("1 cup (130 grams) chopped onion");
recipe1.ingredient.push_back("3 garlic cloves, minced (1 tablespoon)");
recipe1.ingredient.push_back("2 tablespoons tomato paste");
recipe1.ingredient.push_back("1/2 teaspoon dried oregano");
recipe1.ingredient.push_back("Pinch crushed red pepper flakes");
recipe1.ingredient.push_back("1 cup water, broth or dry red wine");
recipe1.ingredient.push_back("1 (28-ounce) can crushed tomatoes");
recipe1.ingredient.push_back("Salt and fresh ground black pepper");
recipe1.ingredient.push_back("Handful fresh basil leaves, plus more for serving");
recipe1.ingredient.push_back("12 ounces dried spaghetti or favorite pasta shape");
recipe1.ingredient.push_back("1/2 cup shredded parmesan cheese");
recipe1.listMaker();

return 0;
}
#include <iostream>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int N;
cin >> N;
int arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
for (int j = N - 1; j >= 0; j--) {
cout << arr[j] << " ";
}

return 0;
}
#include <iostream>
using namespace std;

int main() {
cout << "Hello World!" << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;

string restWord(string str);

int main()
{
string str;
cout << "Enter the string: " << endl;
getline(cin, str);

cout << restWord(str) << endl;

return 0;
}

string  restWord(string str)
{
int cnt=0;
string result ="";

for (int i = 0; !isspace(str[i]) && str.size(); i++)
{
++cnt ;
}

for (int j = cnt + 1; j < str.size(); j++)
{
result += str[j];
}

return result;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;

string firstWord(string str);

int main()
{
string str;
cout << "Enter the string: " << endl;
getline(cin, str);

cout << firstWord(str) << endl;

return 0;
}

string firstWord(string str)
{
string result = "";

for (int i = 0; !isspace(str[i]) && str.size(); i++)
{
result += str[i];
}
return result;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;

int main()
{
string str;
cout << "Enter the string: " << endl;
getline(cin, str);
unsigned int len = str.size();  // intitilize len by its original size

for (int i = 0; i < len ; i++) // keeps incrementing if there is no punctutation
{
if (ispunct(str[i]))
{
str.erase(i, 1);   // erase the element i to one place.
i--;   // new character takes place of the erased one. We are neglecting the effect of loop increment
len = str.size(); // removing the punctutation shrinks the string size
}						// length size changes with every iteration and we give new len value
}

cout << "The word without punctutation is " << str << endl;

return 0;
}
string str;
cout << "Enter the string: " << endl;
getline(cin, str);

for (auto & ind : str)
{
if (ispunct(ind))
ind = ' ';
}

cout << str;
#include <iostream>
#include <string>
using namespace std;
using std::string;
const string hexdigits = "0123456789ABCDEF"; // possible hex digits

int main()
{

cout << "Enter a series of numbers between 0 and 15"
<< " separated by spaces. Hit ENTER when finished: "
<< endl;
string result = ""; // will hold the resulting hexify’d string
unsigned int n; // hold numbers from the input

while (cin >> n )
{
if (n < 16) // ignore invalid input
result += hexdigits[n]; // fetch the indicated hex digit
else if (n == 17)
break;
}

cout << "Your hex number is: " << result << endl;

return 0;
}

#include <iostream>
#include <string>
using namespace std;
using std::string;

int main()
{
string str("helloWorld ");
/*
the for loop terminates at that very time when the condition is not met.
In our case for loop works until the whitespace is met or we go beyond str size
decltype is the almost the same auto, find data type automatically of the expression!!!
*/

for (decltype(str.size()) i = 0; i != str.size() && !isspace(str[i]); i++)
{
str[i] = toupper(str[i]);
}

cout <<"The new string is " << str<< endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;

/*
Remember that a reference is just
another name for a given object. When we use a reference as our control variable,
that variable is bound to each element in the sequence in turn. Using the reference,
we can change the character to which the reference is bound.

*/

int main()
{
string str("HeLLo World");

for (auto &n : str)
{
if (isupper(n))
n=tolower(n);
else
n = toupper(n);
}
cout <<"The new string is " << str<< endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;

int main()
{
string str("AbZal NUrgAzy");

for (auto n : str)
{
if (isupper(n))
cout << (char)(tolower(n));
else
cout << (char)(toupper(n));
}
cout << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;

int main()
{
string name, name1;
char ch;

cout << "Enter any sentence" << endl;    // printing the middle letter
getline(cin, name);
ch = name[name.length()/2];
cout << "The middle letter in the sentence is " << ch << endl;

for (int i = 0; i <= (name.length() / 2)-1; i++)    // printing the first half of the sentence
{
cout << name[i];
}
cout << "\nThe second half " << endl;

for (int i = (name.length() / 2 )+1; i <= name.length(); i++)    // printing the second half of the sentence
{
cout << name[i];
}

return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
string day;
int startTime, minutes;
double cost, rate;
char ch ;

cout << fixed << showpoint << setprecision(2);

do {
cout << "Enter start time of the call(For example, 2:30 = 2330):  " << endl;
cin >> startTime;

while (startTime<0 || startTime>2400) {

cout << "\nInvalid time.";          // keep asking for time input until it is valid
cout << "Enter start time of the call(For example, 2:30 = 2330): ";
cin >> startTime;
}

cout << "Enter length of the call in minutes: ";
cin >> minutes;
cout << "Enter the day of the week: ";
cin >> day;

if (day == "monday" || day == "MONDAY" || day == "tuesday" || day == "TUESDAY" || day == "wednesday" || day == "WEDNESDAY"
|| day == "THURSDAY" || day == "thursday" || day == "friday" || day == "FRIDAY") {

if (startTime >= 800 && startTime <= 1800)
rate = 0.4;
else
rate = 0.25;
cost = minutes * rate;

cout << "\nRate for the call was " << "\$" << rate << " a minute" << endl
<< "Your total cost: " << "\$" << cost << endl;
}

else if (day == "saturday" || day == "SATURDAY" || day == "sunday" || day == "SUNDAY")
{
rate = 0.15;
cost = minutes * rate;
cout << "\Rate for the call was " << "\$" << rate << " a minute" << endl
<< "Your total cost: " << "\$" << cost;

}

else
cout << "\nInvalid.";

cout << "\nWould you like to calculate  your bill again ? (y / n) : ";
cin >> ch;
cout << endl;

}

while (ch == 'Y' || ch == 'y');
cout << "End of programm" <<endl;

return 0;
}
do {
:
:
:
:
else
{
cout << "\nInvalid.";
cout << "\nWould you like to calculate  your bill again ? (y / n) : ";
cin >> ch;
cout << endl;
}

}

while (ch == 'Y' || ch == 'y');
cout << "End of programm" <<endl;
while (startTime<0 || startTime>2400) {

cout << "\nInvalid time.";          // keep asking for time input until it is valid
cout << "Enter start time of the call(For example, 2:30 = 2330): ";
cin >> startTime;
}
#include <iostream>
#include <string>
using namespace std;

int main()
{
cout << "Enter the user name" << endl;

for (int ind = userName.length()-1; ind >= 0; ind--) {
}
cout << endl;

return 0;
}
#include <iostream>
using namespace std;
int const MAX = 60;
int maxinlst(int arr[], int sizeofArr);

int main()
{
int arr[MAX];
int sizeofArr, currNum, maximum;

cout << "Enter the size of the array " << endl;
cin >> sizeofArr;
cout << "Enter the list of numbers" << endl;
for (int i = 0; i < sizeofArr; i++) {
cin >> currNum;
arr[i] = currNum;
}

maximum = maxinlst( arr,sizeofArr);
cout << "The maximum is " << maximum << endl;

return 0;
}

int maxinlst(int arr[], int sizeofArr) {

int max = arr;
for (int i = 1; i < sizeofArr; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
#include <iostream>
using namespace std;
const int MAX_ARRAY = 60;

int main()
{
double average;

cout << "Enter the number of students" << endl;
cin >> numberofStudents;
cout << "Enter the grades separated by a space" << endl;

for (int i = 0; i < numberofStudents; i++) {
}
// calculating the sum and average

sum = 0;
for (int i = 0; i < numberofStudents; i++) {
}
average = (double)sum / (double)numberofStudents;

cout << "the average grade is " << average << endl;
for (int i = 0; i < numberofStudents; i++) {
cout << "The grades that is more than the average is " << grades[i] << endl;
}
}

return 0;
}
#include <iostream>
#include <cmath>
using namespace std;

const int NO_SOLUTION = 0;
const int ONE_REAL_SOLUTION = 1;
const int TWO_REAL_SOLUTIONS = 2;
const int ALL_REALS = 3;
const int NO_REAL_SOLUTIONS = 4;

int linear(double a, double b, double& outX);
int quadratic(double a, double b, double c, double& outX1, double& outX2);

int main()
{
double a, b, c,x1,x2;
cout << "Enter the quadratic equation coefficients" << endl;
cin >> a >> b >> c;

case NO_SOLUTION:
cout << "No solutions" << endl;
break;

case ONE_REAL_SOLUTION:
cout << "One solution: " << x1 << endl;
break;

case TWO_REAL_SOLUTIONS:
cout << "Two real solutions: " << x1 << " and " << x2 << endl;
break;

case ALL_REALS:
cout << "All real number are solutions" << endl;
break;

case NO_REAL_SOLUTIONS:
cout << "No real solutions" << endl;
break;
}

return 0;
}

int quadratic(double a, double b, double c, double& outX1, double& outX2) {

double delta, x1, x2;
delta = b * b - 4 * a * c;

if (delta != 0.0) {

if (delta > 0) {
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
outX1 = x1;
outX2 = x2;
return TWO_REAL_SOLUTIONS;
}

else if (delta == 0.0) {
x1 = -b / (2 * a);
return ONE_REAL_SOLUTION;
}
else
return NO_REAL_SOLUTIONS;
}
else
return linear(b, c, outX1);

}

int linear(double a, double b, double& outX) {
double x;

if (a != 0) {
x = -b / a;
outX = x;
return ONE_REAL_SOLUTION;
}
else if ((a == 0) && (b == 0)) {
x = 0;
outX = x;
return ALL_REALS;
}
else
return NO_SOLUTION;

}
#include <iostream>
using namespace std;

int analyzeDigits(int num, int& outSum);

int main()
{

int num;
int sumDigits, countDigits;

cout << "Enter any nymber to get its sum and number of digits" << endl;
cin >> num;

countDigits = analyzeDigits(num, sumDigits);

cout << num << " has " << countDigits << " digits and their sum is " << sumDigits << endl;

return 0;
}

int analyzeDigits(int num, int& outSum) {

int count = 0, sum = 0;
int currDig;

while (num > 0) {
currDig = num % 10;
sum += currDig;
count++;
num = num / 10;

}

outSum = sum;    // directly changes main variable by reference while one of outputs is returned
return count;

}
#include <iostream>
using namespace std;

int factorial(int num); // <-- remember to include semicolon

// we use prototype of the function to hold the function itself after the main function and show that there is a function with similar name and fuctionality when come across first time.

int main()
{
int n, k, result;

cout << "Please enter the n and k by space" << endl;
cin >> n >> k;

result =  factorial(n) / (factorial(k)*factorial(n-k));

cout << "The result is " << result << endl;

return 0;
}

int factorial(int num) {
int i, factRes;
factRes = 1;

for (i = 1; i <= num;i++) {
factRes *= i;
}

return factRes;
#include <iostream>
using namespace std;

// n choose k, combination method using factorials

int main()
{
int n, k, k_Fact, n_Fact, result, k_nFact;

cout << "Please enter the n and k by space" << endl;
cin >> n >> k;

n_Fact = 1;
for (int i = 1; i <= n; i++) {
n_Fact *= i;
}

k_Fact = 1;
for (int i = 1; i <= k; i++) {
k_Fact *= i;
}

k_nFact = 1;
for (int i = 1; i <= (n-k); i++) {
k_nFact *= i;
}

result = n_Fact / (k_Fact* k_nFact);

cout << "The result is " << result << endl;

return 0;
}
#include <iostream>
using namespace std;

// Fibonacci sequence

int main()
{

int first = 0, second = 1;
int next, num;

cout << "Enter the number of Fibonacci sequence" << endl;
cin >> num;

cout << "Fibonacci series is " << endl;

for (int i = 1; i <= num; ++i) {

cout << first << endl;
next = first + second;
first = second;
second = next;

}

return 0;
}
#include <iostream>
using namespace std;

// here we use flag method to count the average grade

int main()
{
bool seenEndofInput;
int numofStudents, sum;
int curr;
double average;

cout << "Write grades by separated space" << endl;
cout << "End of grades by typing -1" << endl;

numofStudents = 0;
sum = 0;

seenEndofInput = false;

while (seenEndofInput == false) {
cin >> curr;

if (curr == -1) {
seenEndofInput == true;
}
else {
sum += curr;
numofStudents++;
}
}

average = (double)sum / (double)numofStudents;

cout << "The class average grade is " << average << endl;

return 0;
}
#include <iostream>
#include <string>
using namespace std;

int main()
{
int numofStudents;
int curr, sum=0;
double average;

cout << "Please enter number of students" << endl;
cin >> numofStudents;
cout << "Write grades" << endl;

for (int count = 1; count <= numofStudents;++count) {
cin >> curr;
sum += curr;
}
average = (double)(sum / numofStudents);

cout << "The average grade is "<<average << endl;

return 0;
}
#include <iostream>
#include <string>
using namespace std;

/*
375 / 10 = 37;
375 % 10 = 5 ;
So here you are separating one number in one loop from the main number

*/

int main()
{
int countDigits = 0, countSum = 0;
int num,currDigit;

cout << "Enter any number" << endl;
cin >> num;
while (num>0) {
currDigit = (num % 10);
countSum += currDigit;
countDigits++;
num = num / 10;
}

cout << "The sum of digits is: " << countSum << " and the count of digits is: " << countDigits << endl;

return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main()
{
int num;
int even_cnt = 0, odd_cnt=0;
cout << "Write any 4 numbers" << endl;;

for (int i=1; i <= 4; ++i) {
cin >> num;

if (num % 2 == 0) {
++even_cnt;
}
else
++odd_cnt;
}

if (even_cnt > odd_cnt) {
cout << "even numbers are more";
}
else if (even_cnt < odd_cnt) {
cout << "odd numbers are more";
}
else
cout << "they are equal";
return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main()
{

int hour24, minutes24;
int hour12, minutes12;
string period;
char value;

cout << "Enter the time in a 24-hour format \n";
cin >> hour24 >> value >> minutes24;

minutes12 = minutes24;

if (hour24 >= 0 && hour24 <= 11) {
period = "AM";
if (hour24 == 0) {
hour12 = 12;
}
else
hour12 = hour24;
}
else
{
period = "PM";
if (hour24 == 12) {
hour12 = hour24;
}
else
hour12 = hour24 - 12;
}

cout << hour24 << value << minutes24 << " is " << hour12 << value << minutes12<<" " << period << endl;

return 0;
}
#include <iostream>
using namespace std;

int main()
{

char charVal;
cout << "Enter the character"<< endl;
cin >> charVal;
if (charVal >= 'a' && charVal <= 'z') {

cout << "The lowercase character";
}
else if (charVal >= 'A' && charVal <= 'Z') {
cout << "The uppercase character";
}
else if (charVal >= '1' && charVal <= '9') {
cout << "The numeric character";
}
else
cout << "The non alpha-numeric character";

return 0;
}
#include <iostream>
using namespace std;

int main()
{
int dollar, cent, amount, leftover;
int quarter, dime, nickel, penny;

cout << "Write please amount of dollar through space";
cin >> dollar >> cent;

amount = 100 * dollar + cent;
quarter = amount / 25;
leftover = amount % 25;

dime = leftover / 10;
leftover = leftover % 10;

nickel = leftover / 5;
leftover = leftover % 5;

penny = leftover;

cout << "Quarter: " << quarter << endl;
cout << "Dime: " << dime << endl;
cout << "Nickel: " << nickel << endl;
cout << "Penny: " << penny << endl;

return 0;
}

#include <iostream>
using namespace std;

int main()
{

char lowerCase, upperCase;
int offset;

cout << "Enter lowercase letter \n";
cin >> lowerCase;

offset = (int)(lowerCase-'a');
upperCase = (char)('A' + offset);
cout << "Uppercase letter is " << upperCase << endl;

return 0;
}
if (data[c] >= 128)
sum += data[c];
#include<bits/stdc++.h>

using namespace std;

struct node {
int data;
struct node *next;
};

// To create a demo we have to construct a linked list and this
// function is to push the elements to the list.
void push(struct node **head_ref, int data) {
struct node *node;
node = (struct node*)malloc(sizeof(struct node));
node->data = data;
}

// Function to reverse the list
struct node *temp = NULL;
struct node *prev = NULL;
while(current != NULL) {
temp = current->next;
current->next = prev;
prev = current;
current = temp;
}
}

// To check our program
}
}

// Driver function
int main() {
cout << "Linked List Before Reversing" << endl;
cout << endl;
cout << "Linked List After Reversing"<<endl;
return 0;
}
// rdtsc.cpp
// processor: x86, x64
#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(__rdtsc)

int main()
{
unsigned __int64 i;
i = __rdtsc();
printf_s("%I64d ticks\n", i);
}
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// \$1, \$2 for tab stops, \$0 for the final cursor position, and \${1:label}, \${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "cpp boilerplate",
"body": [
"#include<bits/stdc++.h>",
"#define rep(i,a,b) for(int i=a;i<b;i++)",
"#define rrep(i,a,b) for(int i=a;i>=b;i--)",
"#define ll long long",
"#define take(n) ll int n;cin>>n",
"#define mod 1000000007",
"#define mp(a,b) make_pair(a,b)",
"#define pb(a) push_back(a)",
"#define pp pop_back()",
"#define array(n,name) ll int *name=new ll int[n]",
"#define Zubin ios::sync_with_stdio(false);",
"#define Shah cin.tie(NULL);cout.tie(0);",
"using namespace std;\n",
"int main(){\n",
"\tZubin Shah\n",
"\tint N;",
"\tcin>>N;",
"\twhile(N--){",

"\t\t\$1",
"\t}\n",
"return 0;",
"}",
],
"description": "Log output to console",
}
}
public:
int findK(vector<vector<int>> &a, int n, int m, int k)
{
// 1 2 3 4 5
// 6 7 8 9 10
//11 12 13 14 15
//16 17 18 19 20
//21 22 23 24 25
// k=4
// 1 2 3
// 4 5 6
// 7 8 9
// if(k==1) return a;
int lrow=0;
int lcol=0;
int urow=n-1;
int ucol=m-1;
int count=0;
int i=0,j=0;
while(count!=k){
//iterating from left to right
for(j=lcol;j<=ucol;j++){
// cout<<"i:"<<i<<"j:"<<j<<endl;
count++;
if(count==k) {
goto x;
}
}
ucol--;
j--;
//iterating from up to down
for(i=lrow+1;i<=urow;i++){
// cout<<"i:"<<i<<"j:"<<j<<endl;
count++;
if(count==k) {
goto x;
}

}
urow--;
i--;
//iterating from right to left
for(j=ucol;j>=lcol;j--){
// cout<<"i:"<<i<<"j:"<<j<<endl;
count++;
if(count==k) {
goto x;
}

}
lcol++;
j++;
//iterating from down to up
for(i=urow;i>=lrow+1;i--){
//  cout<<"i:"<<i<<"j:"<<j<<endl;
count++;
if(count==k) {
// cout<<"lrow:"<<lrow<<" urow:"<<urow<<" lcol:"<<lcol<<" ucol:"<<ucol<<endl;
goto x;
}

}
lrow++;
i++;

}
x:
return a[i][j];

}
class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
vector<vector<int>>ans(r,vector<int>(c));
int n = mat.size(), m = mat.size();
if(n*m != r*c)  return mat;
int p = 0, q = 0;
for(int i = 0; i < r; ++i) {
for(int j = 0; j < c; ++j) {
ans[i][j] = mat[p][q];
q = (q + 1) % m;
if(q == 0)  p = p + 1;
}
}
return ans;
}
};
// TC - O(n) || SC - O(1)
class Solution {
public:
int maxProfit(vector<int>& prices) {
int n = prices.size() - 1, ans = 0, minSoFar = INT_MAX;
for(int i = 0; i < n; ++i)  {
minSoFar = min(minSoFar, prices[i]);
ans = max(ans, (prices[i] - minSoFar));
}
return ans;
}
};

// we can use auxilary array and store maxSoFar value
class Solution {
public:
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
unordered_map<int,int>mp;
vector<int> ans;
for(int i = 0; i < nums2.size(); ++i)   mp[nums2[i]]++;

for(int i = 0; i < nums1.size(); ++i)   {
if(mp[nums1[i]] > 0)    {
mp[nums1[i]]--;
ans.push_back(nums1[i]);
}
}
return ans;
}
};
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int i = 0, j = numbers.size() - 1;
while(i < j) {
int sum = numbers[i] + numbers[j];
if(sum == target) return {i + 1, j + 1};
else if(sum > target)  j--;
else    i++;
}
return {};
}
};
class Solution {
public:
void moveZeroes(vector<int>& nums) {
for(int i = 0, j = 0; i < nums.size(); i++) {
if(nums[i]) {
swap(nums[i],nums[j++]);
}
}
}
};

//2nd approach
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int zero = 0, one = 0, n = nums.size()-1;
while(zero < n && one < n)  {
while(zero < n && nums[zero] != 0)  {
zero++;
}
one = zero;
while(one < n && nums[one] == 0)    {
one++;
}
swap(nums[zero],nums[one]);
zero++;

}
}
};
class Solution {
public:
void myReverse(vector<int> &nums,int start, int end)   {
while(start < end)  {
swap(nums[start++], nums[end--]);
}
}
void rotate(vector<int>& nums, int k) {
if(nums.size()<2)   return;
k = k % nums.size();
myReverse(nums, 0, nums.size() - k - 1);
myReverse(nums, nums.size()-k, nums.size() - 1);
myReverse(nums, 0 , nums.size() - 1);
}
};
class Solution {
public:
vector<int> sortedSquares(vector<int>& nums) {
vector<int>ans(nums.size());
int first = 0, second = nums.size() - 1;
for(int ind = nums.size() - 1; ind >= 0; ind--)  {
if(abs(nums[first]) < nums[second])
ans[ind] = nums[second] * nums[second--];
else    ans[ind] = nums[first] * nums[first++];
}
return ans;

}
}

//2nd approch
class Solution {
public:
vector<int> sortedSquares(vector<int>& nums) {
vector<int>ans;
int first = 0,second = 0;
while(first<nums.size() && nums[first]<0  ) {
first++;
}
second = first;
first -= 1;
while(first>=0 && second<nums.size())   {
if(abs(nums[first] * nums[first]) < (nums[second] * nums[second]))  {
ans.push_back(nums[first] * nums[first]);
first--;
}
else {
ans.push_back(nums[second] * nums[second]);
second++;
}
}
while(first>=0) {
ans.push_back(nums[first] * nums[first]);
first--;
}
while(second<nums.size())   {
ans.push_back(nums[second] * nums[second]);
second++;
}
return ans;

}
};
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_set<int>st(nums.begin(), nums.end());
cout<<nums.size()<<"  "<<st.size()<<endl;
return (nums.size() == st.size()) ? false : true;
}
};
class Solution {
public:
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
int p = m-1, q = n-1, ind = nums1.size()-1;
while(p>=0 && q>=0) {
if(nums2[q] > nums1[p]) {
nums1[ind--] = nums2[q];
q--;
}
else    {
nums1[ind--] = nums1[p];
p--;
}
}
while(q >= 0)    {
nums1[ind--] = nums2[q--];
}
}
};
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int n = digits.size();
for(int i = n-1; i >=0 ; --i)   {
if((digits[i] + 1) > 9) {
digits[i] = 0;
}
else    {
digits[i] += 1;
return digits;
}
}
digits.push_back(0);
digits = 1;
return digits;
}
};
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int n = nums.size(), lMax = 0, gMax = nums;
for(int i = 0; i < n; ++i)    {
lMax += nums[i];
gMax = max(gMax, lMax);
if(lMax<0)
lMax = 0;
}
return gMax;
}
};
// Using While Loop
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int start = 0, end = nums.size()-1;
while(start<=end)    {
int mid = (start+end)/2;
if(nums[mid] == target) return mid;
else if(nums[mid] < target)
start = mid+1;
else
end = mid-1;
}
return start;
}
};

//Using Recursion
class Solution {
public:
int BinSearch(vector<int>nums,int start, int end, int target) {
if(end < start) {
return start;
}
int mid = (start + end) / 2;
if(nums[mid] == target) {
return mid;
}
else if(nums[mid] < target) {
return BinSearch(nums, mid+1, end, target);
}
else {
return BinSearch(nums, start, mid-1,target);
}
}
int searchInsert(vector<int>& nums, int target) {
return BinSearch(nums,0,nums.size()-1,target);
}
};
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int start = 0, end = nums.size(),ans=0;
while(start < end)  {
if(nums[start] == val)  {
swap(nums[start],nums[end-1]);
end--;
}
else start++;
}
return end;
}
};
SDL_Rect rsc{}, dst{};
for (const Tile& tile : m_pTiles)
{
rsc.x = static_cast<int>((m_LevelNumber * m_TileSize.x * 3) + m_TileSize.x * int(tile.tileState));
rsc.y = 0;
rsc.w = static_cast<int>(m_TileSize.x);
rsc.h = static_cast<int>(m_TileSize.y);

dst.x = static_cast<int>(tile.pos.x);
dst.y = static_cast<int>(tile.pos.y);
dst.w = static_cast<int>(m_TileSize.x);
dst.h = static_cast<int>(m_TileSize.y);

kaas::Renderer::GetInstance().RenderTexture(*m_pTexture, dst, rsc);
}

for (const Disc& disc : m_pPossibleDiscLocations)
{
if (disc.level == m_LevelNumber)
{
kaas::Renderer::GetInstance().RenderTexture(*m_pDiscTexture, disc.pos.x, disc.pos.y);
}
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define take(n) ll int n;cin>>n
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;

int main()
{
// Zubin Shah
int N;
cin>>N;
while(N--)
{
take(n);
vector<int> vect;
vect.pb(1);
ll carry=0;
int number_of_digits=1;
rep(i,2,n+1){
rep(j,0,number_of_digits){
ll temp=(vect[j]*i)+carry;
vect[j]=temp%10;
carry=temp/10;
}
while(carry>0){
ll temp=carry%10;
vect.pb(temp);
carry/=10;
number_of_digits++;
}
}
rrep(i,number_of_digits-1,0){
cout<<vect[i];
}
cout<<endl;
}

return 0;
}
vector* sum( vector* v, int n ) {
vector* r = ( vector* )( malloc( sizeof( vector ) ) );
for( i = 0; i < n; i++ ) {
r = add( r, v + i );
}

return r;
}
typedef struct __vector {
int x;
int y;
} vector;

vector* add( vector* a, vector* b ) {
vector* r = ( vector* )( malloc( sizeof( vector ) ) );
r->x = a->x + b->x;
r->y = a->y + b->y;

return r;
}
a = a ^ b;
b = a ^ b;
a = a ^ b;
#include <iostream>

using namespace std;

int main()
{
cout<<"Hello World";

return 0;
}
// O(n) Linear search
void MinMaxValue(vector<int>arr)  {
int mini = arr, maxi = arr;
for(int i=1;i<arr.size();i++)   {
if(arr[i]<mini)
mini = arr[i];
if(arr[i]>maxi)
maxi = arr[i];
}
cout<<mini<<" "<<maxi;
}
// TWO POINTER APPROCH
void reverseString(vector<char>& s) {
int start=0,end=s.size()-1;
while(start<end)
swap(s[start++],s[end--]);
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ull unsigned long long
using namespace std;
void merge(int *arr1,int *arr2,int n, int m){
int i=0,j=0,k=0;
int maxi=INT_MIN;
rep(i,0,n) maxi=max(arr1[i],maxi);
rep(i,0,m) maxi=max(arr2[i],maxi);
maxi++;
while(i<n && j<m){
int x=arr1[i]%maxi;
int y=arr2[j]%maxi;
if(x<y){
if(k<n)  arr1[k]+=x*maxi;
else  arr2[k-n]+=x*maxi;
k++;
i++;
}
else{
if(k<n)  arr1[k]+=y*maxi;
else arr2[k-n]+=y*maxi;
k++;
j++;
}
}
while(i<n){
int x=arr1[i]%maxi;
if(k<n) arr1[k]+=x*maxi;
else arr2[k-n]+=x*maxi;
k++;
i++;
}
while(j<m){
int x=arr2[j]%maxi;
if(k<n) arr1[k]+=x*maxi;
else  arr2[k-n]+=x*maxi;
k++;
j++;
}
rep(i,0,n) arr1[i]=arr1[i]/maxi;
rep(i,0,m) arr2[i]=arr2[i]/maxi;
}
int main()
{
int N;
cin>>N;
while(N--)
{
int n,m;
cin>>n>>m;
int *arr1=new int[n];
int *arr2=new int[m];
rep(i,0,n) cin>>arr1[i];
rep(i,0,m) cin>>arr2[i];
merge(arr1,arr2,n,m);
rep(i,0,n) cout<<arr1[i]<<" ";
rep(i,0,m) cout<<arr2[i]<<" ";
cout<<endl;
}

return 0;
}
uint64_t rdtsc() {
uint32_t hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));

return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 );
}
#include<iostream>
using namespace std;

int main(){
int n;
cin >> n;
cout << "Hello!" << n;
return 0;
}
class Solution {
public:
bool isSubsequence(string s, string t) {
int i = t.length()-1;
int j = s.length() - 1;
while(i>=0 & j>=0){
if(t[i]==s[j]){
i--;
j--;
}
else{
i--;
}

}
if(j==-1){
return true;
}
return false;
}
};
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ull unsigned long long
using namespace std;
bool check(pair<ull,ull> timing1,pair<ull,ull> timing2){
return timing1.first>timing2.first ? false:true;
}
int waiting_time(pair<ull,ull> *timing,ull time,int n){
int s=0,e=n-1;
while(s<=e){
ull mid=(s+e)/2;
if(timing[mid].first>time){
if(mid==0 || timing[mid-1].second<=time){
return timing[mid].first-time;
}
e=mid-1;
}
else if(timing[mid].first<time){
if(timing[mid].second>time) return 0;
s=mid+1;
}
else return 0;
}
return -1;
}
int main()
{
int N;
cin>>N;
while(N--)
{
int n,m;
cin>>n>>m;
pair<ull,ull> *timing=new pair<ull,ull>[n];
rep(i,0,n) cin>>timing[i].first>>timing[i].second;
sort(timing,timing+n,check);
ull *people=new ull[m];
rep(i,0,m)  {
cin>>people[i];
cout<<waiting_time(timing,people[i],n)<<endl;
}
}

return 0;
}
int ref = x;
int y;
int rev =0;
if(x<0) return 0;
if(x==0) return 1;
if(x>INT_MIN || x<INT_MAX)
{
while(x)
{
y=x%10;
x=x/10;
if(rev > INT_MAX/10 || (rev == INT_MAX / 10 && y>7)) return 0;
if(rev < INT_MIN/10 || (rev == INT_MIN / 10 && y<-8)) return 0;
rev=rev*10+y;
}

}
cout <<rev<<"\n";
if(ref == rev)
return rev;
else
return 0;
class Solution {
public:
int reverse(int x) {
int y;
int rev =0;
if(x>INT_MIN || x<INT_MAX)
{
while(x)
{
y=x%10;
x=x/10;
if(rev > INT_MAX/10 || (rev == INT_MAX / 10 && y>7)) return 0;
if(rev < INT_MIN/10 || (rev == INT_MIN / 10 && y<-8)) return 0;
rev=rev*10+y;
}

}
return rev;
}
};
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> I;

int y;
for (int x=0; x<nums.size(); x++)
{
y=0;
for (int z=x+1; z<nums.size(); z++)
{
y=nums[x]+nums[z];
if(y==target)
{
I.push_back(x);
I.push_back(z);
break;
}
}

}

return I;
}
};
/**
* class ListNode {
*     val: number
*     next: ListNode | null
*     constructor(val?: number, next?: ListNode | null) {
*         this.val = (val===undefined ? 0 : val)
*         this.next = (next===undefined ? null : next)
*     }
* }
*/

function reverseBetween(head: ListNode | null, left: number, right: number): ListNode | null {

return null;

let currPtr = head, prevPtr = null;

while (left > 1) {
prevPtr = currPtr;
currPtr = currPtr.next;

left--;
right--;
}

let tailPtr = currPtr, connPtr = prevPtr, thirdPtr: ListNode | null = null;

while (right > 0) {
thirdPtr = currPtr.next;
currPtr.next = prevPtr;
prevPtr = currPtr;
currPtr = thirdPtr;

right--;
}

if (connPtr)
connPtr.next = prevPtr;
else

tailPtr.next = currPtr;

};
#include<iostream>
using namespace std;
bool issafe(int** arr,int x,int y,int n){
for(int row=0;row<x;row++){
if(arr[row][y]==1) return false;
}
int row=x-1;
int col=y-1;
while(row>=0 && col>=0){
if(arr[row][col]==1)return false;
row--;
col--;
}
row=x-1;
col=y+1;
while(row>=0 && col<n){
if(arr[row][col]==1)  return false;
row--;
col++;
}
return true ;
}
bool nqueen(int** arr,int n,int x=0){
if(x>=n) return true;
for(int col=0;col<n;col++){
if(issafe(arr,x,col,n)){
arr[x][col]=1;
if(nqueen(arr,n,x+1)) return true;
arr[x][col]=0;  //backtracking
}
}
return false;
}
int main(){
int n;
cin>>n;
int **arr=new int*[n];
for(int i=0;i<n;i++){
arr[i]=new int[n];
for(int j=0;j<n;j++) arr[i][j]=0;
}
if(nqueen(arr,n)){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) cout<<arr[i][j]<<" ";
cout<<endl;
}
}
return 0;
}
#include<iostream>
using namespace std;
bool issafe(int** arr,int x,int y,int n){
for(int row=0;row<=x;row++){
if(arr[x][y]==1){
return false;
}
}
int row=x;
int col=y;
while(row>=0 && col>=0){
if(arr[row][col]==1){
return false;
}
row--;
col--;
}
row=x;
col=y;
while(row>=0 && col<n){
if(arr[row][col]==1){
return false;
}
row--;
col++;
}
return true ;
}
bool nqueen(int** arr,int x,int n){
if(x>=n){
return true;
}
for(int col=0;col<=n;col++){
if(issafe(arr,x,col,n)){
arr[x][col]==1;
if(nqueen(arr,x+1,n)){
return true;
}
arr[x][col]=0;  //backtracking

}
}
return false;
}
int main(){
int n;
cin>>n;
int** arr=new int*[n];
for(int i=0;i<n;i++){
arr[i]=new int[n];
for(int j=0;j<n;j++){
arr[i][j]=0;

}
}
if(nqueen(arr,0,n)){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<arr[i][j]<<"";
}cout<<endl;
}
}

return 0;
}
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
int search(vector<int> arr,int n,int x){
int low=0,high=n-1;
while(low<=high){
int mid=low+(high-low)/2;
if(arr[mid]>x){
high=mid-1;
}
else if(arr[mid]<x){
low=mid+1;
}
else{
return mid;
}
}
return low;
}
vector<int> findClosestElements(vector<int>& arr, int k, int x) {
vector<int> ans;
int n=arr.size();
int i=search(arr,n,x);
int l=i-1,r=i;
while(k>0){
if(l<0 || (r<n && abs(arr[l]-x)>abs(arr[r]-x))){
r++;
}
else{
l--;
}
k--;
}
l++;
while(l<r){
ans.push_back(arr[l]);
l++;
}
return ans;
}
};
int main(){
Solution s;
vector<int> a={1,2,3,4,5};
int k=3,x=2;
vector<int> ans=s.findClosestElements(a,k,x);
for(auto i:ans){
cout<<i<<" ";
}cout<<endl;
return 0;
}
#include<iostream>
#include<unordered_map>
#include<queue>
#define rep(i,a,b) for(long int i=a;i<b;i++)
#define ull unsigned long long
using namespace std;

int main()
{
long int a,b,c;
cin>>a>>b>>c;
unordered_map<int,int> um;
// int *array1=new int[a];
int *array1=new int[a];
int *array2=new int[b];
int *array3=new int[c];
rep(i,0,a) {
cin>>array1[i];
um[array1[i]]++;
}
rep(i,0,b) {
cin>>array2[i];
}
rep(i,0,c) {
cin>>array3[i];
}
queue<int> output;
long int count=0;
long  int i=0,j=0;
while(i<b && j<c){
if(array2[i]>array3[j]){
if(um.find(array3[j])!=um.end()){
count++;
output.push(array3[j]);
}
j++;
}
else if(array2[i]<array3[j]){
if(um.find(array2[i])!=um.end()){
count++;
output.push(array2[i]);
}
i++;
}
else{
count++;
output.push(array2[i]);
i++;
j++;
}
}
while(i<b){
if(um.find(array2[i])!=um.end()) {
count++;
output.push(array2[i]);
}
i++;
}
while(j<c){
if(um.find(array3[j])!=um.end()) {
count++;
output.push(array3[j]);
}
j++;
}
cout<<count<<endl;
while(!output.empty())
{
cout<<output.front()<<endl;
output.pop();
}

return 0;
}
// python
def isbright(image, dim=10, thresh=0.5):
# Resize image to 10x10
image = cv2.resize(image, (dim, dim))
# Convert color space to LAB format and extract L channel
L, A, B = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2LAB))
# Normalize L channel by dividing all pixel values with maximum pixel value
L = L/np.max(L)
# Return True if mean is greater than thresh else False
return np.mean(L) > thresh

// c++
bool rockface_image_is_bright(cv::Mat img_mat, int dim, float threshold)
{
// Resize image to 10x10
cv::resize(img_mat, img_mat, { dim, dim });

// Convert color space to LAB format and extract L channel
cv::cvtColor(img_mat, img_mat, cv::COLOR_RGB2Lab);
cv::Mat labchannel;
cv::split(img_mat, labchannel);

cv::imshow("L", labchannel);
cv::waitKey(0);

// Normalize L channel by dividing all pixel values with maximum pixel value
cv::Mat L;
cv::normalize(labchannel, L, 0, 1, cv::NORM_MINMAX);

// Return True if mean is greater than thresh else False
float brightness = cv::mean(L).val;
std::cout << "brightness: " << brightness << std::endl;
return brightness > threshold;
}
void reverseStr(string& str)
{
int n = str.length();

// Swap character starting from two
// corners
for (int i = 0; i < n / 2; i++)
swap(str[i], str[n - i - 1]);
}

class Solution
{
public:
void merge(int arr[], int l, int m, int r)
{
int n1=m-l+1;
int n2=r-m;
// Initialization of temp arrays
int L[n1],R[n2];
// Initialization of first subarray
for(int i=0;i<n1;i++)
L[i]=arr[l+i];
// Initialization of second subarray
for(int j=0;j<n2;j++)
R[j]=arr[m+1+j];
int i=0,j=0,k=l;
//Sorting the array using subarrays
while(i<n1&&j<n2){
if(L[i]<R[j]){
arr[k]=L[i];
i++;
}
else {
arr[k]=R[j];
j++;
}
k++;
}
//Remaining elements added to the array
while(i<n1){
arr[k]=L[i];
i++;k++;
}
while(j<n2){
arr[k]=R[j];
j++;k++;
}
}
public:
void mergeSort(int arr[], int l, int r)
{
if(l>=r)
return; //returns recursively
int m=l+(r-l)/2;
mergeSort(arr,l,m);
mergeSort(arr,m+1,r);
merge(arr,l,m,r);
}
};
class Solution
{
public:
void insertionSort(int arr[], int n)
{
int value,hole;
for(int i=0;i<n;i++){
value=arr[i];hole=i;
while(hole>0&&arr[hole-1]>value){
arr[hole]=arr[hole-1];
hole--;
}
arr[hole]=value;
}
}
};
class Solution
{
public:
int select(int arr[], int i)
{
int max = arr, ind = 0;
int j;
for ( j=1; j<=i; j++)
{
if (arr[j] > max)
{
ind = j;
max = arr[j];
}
}
return ind;
}

void selectionSort(int arr[], int n)
{
int i, j;
for (i = n-1; i >=0; i--)
{
int j = select(arr, i);
swap(&arr[i], &arr[j]);
}
}
};
class Solution
{
public:
//Function to sort the array using bubble sort algorithm.
void bubbleSort(int arr[], int n)
{
int flag=0;
for(int k=1;k<=n-1;k++){
for(int j=0;j<=n-k-1;j++){
if(arr[j]>arr[j+1]){
swap(&arr[j],&arr[j+1]);
flag=1;
}
}
if(flag==0)
break;
}
}
void swap(int *xp,int *yp){
int temp=*xp;
*xp=*yp;
*yp=temp;
}
};
class int_ptr_wrapper
{
public:
int_ptr_wrapper(int value = 0) :
mInt(new int(value))
{}

// note! needs copy-constructor and copy-assignment operator!

~int_ptr_wrapper()
{
delete mInt;
}

private:
int* mInt;
};
class Wrapper
{
private:
CLib *lib;

public:
Wrapper() { lib = lib_init(); } // Lib initialisieren
~Wrapper() { lib_cleanup(&init); } // Lib freigeben

std::string DoSomething()
{
char *cstr = lib_get_str(); // String anfordern (malloc!)

std::string s = str;  // in std::string kopieren

lib_free_str(cstr); // String freigeben (free)

return s; // std::string zurückgeben. Alles easy.
}
};
///LIBRARIES & SPECIFIC PARAMETERS
#include <Arduino.h>
#include <Wire.h>
#include <U8g2lib.h>

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //OLED Constructor

//- - - - VARIABLES & METHODS - - - -//

#define jky 13              //Joystick button pin
#define emgPin A0           //EMG signal pin
#define emgThreshold 500    //EMG signal detection threshold

/*----OLED Display & Driver----*/
void u8g2_prepare(void) {
u8g2.setFontMode(1);              //Enable Transparent Font
u8g2.setFont(u8g2_font_6x13_tf);  //Set font Width: 6px / Height: 13px
u8g2.setFontRefHeightExtendedText();
u8g2.setFontPosTop();             //Origin Position of Text
u8g2.setFontDirection(0);         //Font direction 0º
}
//Custom Drawn Symbols
static const unsigned char back[] U8X8_PROGMEM  = {
0x04, 0x06, 0x7F, 0x86, 0x84, 0x60, };

/*---- Servo Driver Variables ----*/
#define Freq (uint8_t) 50     //Servo working frequency

#define posMin 102
#define posMax 512

//Finger Number Assignation for Servo Control
#define thumb (uint8_t) 0
#define index (uint8_t) 1
#define middle (uint8_t) 2
#define ring (uint8_t) 3
#define pinky (uint8_t) 4
#define wrist (uint8_t) 5

//Method to map servo position from pulses to degrees
void setServo(uint8_t n_servo, uint8_t angulo){
int duty;
duty=map(angulo, 0, 180, posMin, posMax);
servo.setPWM(n_servo, 0, duty);
}

//Method for EMG signal detection and actuation
void emg(void (*pointer)()){
pointer();
}
else{
openHand();
}
}

/*---- Hand Movements Methods ----*/
void closeHand(void){
setServo(thumb,170);
setServo(index,170);
setServo(middle,175);
setServo(ring,151);
setServo(pinky,161);
setServo(wrist,180);
}
void openHand(void){
setServo(thumb,13);
setServo(index,10 );
setServo(middle,13);
setServo(ring,13);
setServo(pinky,13);
setServo(wrist,180);
}
void rock_servo(void){
setServo(thumb,170);
setServo(index,13);
setServo(middle,175);
setServo(ring,151);
setServo(pinky,13);
setServo(wrist,180);
}
void ronaldinho_servo(){
setServo(thumb,13);
setServo(index,156);
setServo(middle,145);
setServo(ring,151);
setServo(pinky,13);
setServo(wrist,150);
delay(400);
setServo(wrist,180);
delay(500);
}
}
void point_servo(void){
setServo(thumb,170);
setServo(index,13);
setServo(middle,145);
setServo(ring,151);
setServo(pinky,161);
setServo(wrist,180);
}
void thumbsUp_servo(void){
setServo(thumb,13);
setServo(index,156);
setServo(middle,145);
setServo(ring,151);
setServo(pinky,161);
setServo(wrist,180);
}

/*---- Joystick Button----*/
#define jkyX A1
#define jkyY A2

uint8_t swbtn_state=0;    // Memory Storage Byte
bool btn_val=0;           // Current state of the button
bool btn_oldVal=1;        // Previous state of the button

//Joystick Button Method
void btn_Jky(uint8_t x){
if (btn_val == LOW && btn_oldVal == HIGH){
swbtn_state=x;
delay(10);
}
btn_oldVal=btn_val;
}

/*- *- *- *- - MENU SYSTEM - -* -* -* -*/
uint8_t M1 = 0; //Memory variable to determine menu state
uint8_t F1 = 0; //Memory variable to determine menu state
uint8_t C1 = 0; //Memory variable to determine menu state

//Mode_options
#define openClose (uint8_t) 1
#define figures (uint8_t)   2
#define custom  (uint8_t)   3

//Figures_options
#define rock (uint8_t)       1
#define ronaldinho (uint8_t) 2
#define point (uint8_t)      3
#define thumbUp (uint8_t)    4
#define goBackF1 (uint8_t)   5

//Custom_options
#define thumb (uint8_t)    1
#define index (uint8_t)    2
#define middle (uint8_t)   3
#define ring (uint8_t)     4
#define pinky (uint8_t)    5
#define wrist (uint8_t)    6
#define goBackC1 (uint8_t) 7

/*-- Read Joystic M1 Method --*/
void jkyM1(void){
M1 = openClose;
}
M1 = figures;
}
M1 = custom;
}
}

/*---- Modes Screen Methods ----*/
void M1_openClose(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(32, 45, "OPEN/CLOSE");

u8g2.drawBox(8,0,31,31);   //Selected box
u8g2.drawStr(21,9, "1");   //Selected string

u8g2.drawFrame(47,0,31,31);
u8g2.drawStr(60,9, "2");

u8g2.drawFrame(86,0,31,31);
u8g2.drawStr(99,9, "3");

u8g2.sendBuffer();
}
void M1_openClose_in(){
emg(closeHand);
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(32, 16, "Squeeze to");
u8g2.drawStr(32, 32, "CLOSE HAND");

u8g2.sendBuffer();
}
void M1_figures(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(42, 45, "FIGURES");

u8g2.drawFrame(8,0,31,31);
u8g2.drawStr(21,9, "1");

u8g2.drawBox(47,0,31,31);   //Selected box
u8g2.drawStr(60,9, "2");    //Selected string

u8g2.drawFrame(86,0,31,31);
u8g2.drawStr(99,9, "3");

u8g2.sendBuffer();
}
void M1_custom(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(19, 45, "CUSTOM MOVEMENT");

u8g2.drawFrame(8,0,31,31);
u8g2.drawStr(21,9, "1");

u8g2.drawFrame(47,0,31,31);
u8g2.drawStr(60,9, "2");

u8g2.drawBox(86,0,31,31);   //Selected box
u8g2.drawStr(99,9, "3");    //Selected string

u8g2.sendBuffer();
}

void modes_M1(){
switch (M1){
case openClose:
if(swbtn_state==1){
M1_openClose_in();
btn_Jky(0);
}
else{
jkyM1();
openHand();
M1_openClose();
btn_Jky(1);
}
break;

case figures:
if(swbtn_state==2 || swbtn_state==3){
figures_F1();
}
else{
jkyM1();
openHand();
M1_figures();
btn_Jky(2);
}
break;

case custom:
if(swbtn_state==4 || swbtn_state==5){
custom_C1();
}
else{
jkyM1();
openHand();
M1_custom();
btn_Jky(4);
}
break;
}
}

/*-- Read Joystic F1 Method --*/
void jkyF1(void){
F1 = rock;
}
F1 = ronaldinho;
}
F1 = point;
}
F1 = thumbUp;
}
F1 = goBackF1;
}
}

/*---- Figures Screen Methods ----*/
void F1_rock(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(32, 32, "ROCK'N ROLL");

u8g2.drawBox(11,0,17,17);   //Selected box
u8g2.drawStr(17,2, "1");    //Selected string

u8g2.drawFrame(39,0,17,17);
u8g2.drawStr(45,2, "2");

u8g2.drawFrame(67,0,17,17);
u8g2.drawStr(73,2, "3");

u8g2.drawFrame(95,0,17,17);
u8g2.drawStr(101,2, "4");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();

}
void F1_rock_in(void){
emg(rock_servo);
btn_Jky(2);
u8g2.clearBuffer();

u8g2.drawStr(32, 16, "Squeeze to");
u8g2.drawStr(32, 32, "ROCK'N ROLL");

u8g2.sendBuffer();
}
void F1_ronaldinho(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(34, 32, "RONALDINHO");

u8g2.drawFrame(11,0,17,17);
u8g2.drawStr(17,2, "1");

u8g2.drawBox(39,0,17,17);   //Selected box
u8g2.drawStr(45,2, "2");    //Selected string

u8g2.drawFrame(67,0,17,17);
u8g2.drawStr(73,2, "3");

u8g2.drawFrame(95,0,17,17);
u8g2.drawStr(101,2, "4");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}
void F1_ronaldinho_in(void){
emg(ronaldinho_servo);
btn_Jky(2);
u8g2.clearBuffer();

u8g2.drawStr(32, 32, "RONALDINHO!");

u8g2.sendBuffer();
}
void F1_point(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(49, 32, "POINT");

u8g2.drawFrame(11,0,17,17);
u8g2.drawStr(17,2, "1");

u8g2.drawFrame(39,0,17,17);
u8g2.drawStr(45,2, "2");

u8g2.drawBox(67,0,17,17);   //Selected box
u8g2.drawStr(73,2, "3");    //Selected string

u8g2.drawFrame(95,0,17,17);
u8g2.drawStr(101,2, "4");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}
void F1_point_in(void){
emg(point_servo);
btn_Jky(2);
u8g2.clearBuffer();

u8g2.drawStr(32, 16, "Squeeze to");
u8g2.drawStr(49, 32, "POINT");

u8g2.sendBuffer();
}
void F1_thumbUp(){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(39, 32, "THUMBS UP");

u8g2.drawFrame(11,0,17,17);
u8g2.drawStr(17,2, "1");

u8g2.drawFrame(39,0,17,17);
u8g2.drawStr(45,2, "2");

u8g2.drawFrame(67,0,17,17);
u8g2.drawStr(73,2, "3");

u8g2.drawBox(95,0,17,17);     //Selected box
u8g2.drawStr(101,2, "4");     //Selected string

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}
void F1_thumbUp_in(void){
emg(thumbsUp_servo);
btn_Jky(2);
u8g2.clearBuffer();

u8g2.drawStr(20, 16, "Squeeze to give");
u8g2.drawStr(32, 30, "a THUMBS UP");

u8g2.sendBuffer();
}
void F1_goBack(void){
btn_Jky(0);
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(42, 32, "GO BACK");

u8g2.drawFrame(11,0,17,17);
u8g2.drawStr(17,2, "1");

u8g2.drawFrame(39,0,17,17);
u8g2.drawStr(45,2, "2");

u8g2.drawFrame(67,0,17,17);
u8g2.drawStr(73,2, "3");

u8g2.drawFrame(95,0,17,17);
u8g2.drawStr(101,2, "4");

u8g2.drawBox(115,51,12,10);   //Selected box

u8g2.setDrawColor(0);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

//MAIN FIGURES METHOD
void figures_F1(){
switch (F1){
case rock:
if(swbtn_state==3){ //s'ha de canviar!!
F1_rock_in();
}
else{
btn_Jky(3);
jkyF1();
F1_rock();  //print on display F1_rock
}
break;

case ronaldinho:
if(swbtn_state==3){ //s'ha de canviar!!
F1_ronaldinho_in();
}
else{
btn_Jky(3);
jkyF1();
F1_ronaldinho(); //print on display F1_ronaldinho
}
break;

case point:
if(swbtn_state==3){ //s'ha de canviar!!
F1_point_in();
}
else{
btn_Jky(3);
jkyF1();
F1_point(); //print on display F1_ronaldinho
}
break;

case thumbUp:
if(swbtn_state==3){ //s'ha de canviar!!
F1_thumbUp_in();
}
else{
btn_Jky(3);
jkyF1();
F1_thumbUp(); //print on display F1_ronaldinho
}
break;

case goBackF1:
jkyF1();
F1_goBack(); //print on display F1_ronaldinho
break;
}
}

/*-- Read Joystic C1 Method --*/
void jkyC1(void){
C1 = thumb;
}
C1 = index;
}
C1 = middle;
}
C1 = ring;
}
C1 = pinky;
}
C1 = wrist;
}
C1 = goBackC1;
}
}
/*-- Movement State for Individual Fingers Method --*/
uint8_t movement=0;
void jky_servo_movement(void){
movement=1;
}
movement=2;
}
movement=0;
}
}

/*---- Custom Screen Methods ----*/
void C1_thumb(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(49, 32, "THUMB");

u8g2.drawBox(2,0,17,17);   //Selected box
u8g2.drawStr(8,2, "1");    //Selected string

u8g2.drawFrame(23,0,17,17);
u8g2.drawStr(29,2, "2");

u8g2.drawFrame(44,0,17,17);
u8g2.drawStr(50,2, "3");

u8g2.drawFrame(65,0,17,17);
u8g2.drawStr(71,2, "4");

u8g2.drawFrame(86,0,17,17);
u8g2.drawStr(92,2, "5");

u8g2.drawFrame(107,0,17,17);
u8g2.drawStr(113,2, "6");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

#define thumbMin 13
#define thumbMax 170
uint8_t thumb_angle=13;
uint8_t thumb_percentage=0;

void C1_thumb_in(void){
jky_servo_movement();
btn_Jky(4);
if(movement==1 && thumb_angle<thumbMax){
thumb_angle++;
}
else if(movement==2 && thumb_angle>thumbMin){
thumb_angle--;
}
setServo(0,thumb_angle);
thumb_percentage=map(thumb_angle, thumbMin, thumbMax, 0, 100);
String percentage = String(thumb_percentage);

u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(12,24, "Thumb:");
u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
u8g2.drawStr(82,24, "%");

u8g2.drawFrame(12,40,102,17);
u8g2.drawBox(13,41,thumb_percentage,15);   //x is percentage of map

u8g2.sendBuffer();

}
void C1_index(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(49, 32, "INDEX");

u8g2.drawFrame(2,0,17,17);
u8g2.drawStr(8,2, "1");

u8g2.drawBox(23,0,17,17);   //Selected box
u8g2.drawStr(29,2, "2");     //Selected string

u8g2.drawFrame(44,0,17,17);
u8g2.drawStr(50,2, "3");

u8g2.drawFrame(65,0,17,17);
u8g2.drawStr(71,2, "4");

u8g2.drawFrame(86,0,17,17);
u8g2.drawStr(92,2, "5");

u8g2.drawFrame(107,0,17,17);
u8g2.drawStr(113,2, "6");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

#define indexMin 10
#define indexMax 170
uint8_t index_angle=10;
uint8_t index_percentage=0;

void C1_index_in(){
jky_servo_movement();
btn_Jky(4);
if(movement==1 && index_angle<indexMax){
index_angle++;
}
else if(movement==2 && index_angle>indexMin){
index_angle--;
}
setServo(1,index_angle);
index_percentage=map(index_angle, indexMin, indexMax, 0, 100);
String percentage = String(index_percentage);

u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(12,24, "Index:");
u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
u8g2.drawStr(82,24, "%");

u8g2.drawFrame(12,40,102,17);
u8g2.drawBox(13,41,index_percentage,15);   //x is percentage of map

u8g2.sendBuffer();
}
void C1_middle(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(47, 32, "MIDDLE");

u8g2.drawFrame(2,0,17,17);
u8g2.drawStr(8,2, "1");

u8g2.drawFrame(23,0,17,17);
u8g2.drawStr(29,2, "2");

u8g2.drawBox(44,0,17,17);   //Selected box
u8g2.drawStr(50,2, "3");    //Selected string

u8g2.drawFrame(65,0,17,17);
u8g2.drawStr(71,2, "4");

u8g2.drawFrame(86,0,17,17);
u8g2.drawStr(92,2, "5");

u8g2.drawFrame(107,0,17,17);
u8g2.drawStr(113,2, "6");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

#define middleMin 13
#define middleMax 175
uint8_t middle_angle=13;
uint8_t middle_percentage=0;

void C1_middle_in(void){
jky_servo_movement();
btn_Jky(4);
if(movement==1 && middle_angle<middleMax){
middle_angle++;
}
else if(movement==2 && middle_angle>middleMin){
middle_angle--;
}
setServo(2,middle_angle);
middle_percentage=map(middle_angle, middleMin, middleMax, 0, 100);
String percentage = String(middle_percentage);

u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(12,24, "Middle:");
u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
u8g2.drawStr(82,24, "%");

u8g2.drawFrame(12,40,102,17);
u8g2.drawBox(13,41,middle_percentage,15);   //x is percentage of map

u8g2.sendBuffer();
}
void C1_ring(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(52, 32, "RING");

u8g2.drawFrame(2,0,17,17);
u8g2.drawStr(8,2, "1");

u8g2.drawFrame(23,0,17,17);
u8g2.drawStr(29,2, "2");

u8g2.drawFrame(44,0,17,17);
u8g2.drawStr(50,2, "3");

u8g2.drawBox(65,0,17,17);   //Selected box
u8g2.drawStr(71,2, "4");    //Selected string

u8g2.drawFrame(86,0,17,17);
u8g2.drawStr(92,2, "5");

u8g2.drawFrame(107,0,17,17);
u8g2.drawStr(113,2, "6");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

#define ringMin 13
#define ringMax 151
uint8_t ring_angle=13;
uint8_t ring_percentage=0;

void C1_ring_in(void){
jky_servo_movement();
btn_Jky(4);
if(movement==1 && ring_angle<ringMax){
ring_angle++;
}
else if(movement==2 && ring_angle>ringMin){
ring_angle--;
}
setServo(3,ring_angle);
ring_percentage=map(ring_angle, ringMin, ringMax, 0, 100);
String percentage = String(ring_percentage);

u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(12,24, "Ring:");
u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
u8g2.drawStr(82,24, "%");

u8g2.drawFrame(12,40,102,17);
u8g2.drawBox(13,41,ring_percentage,15);   //x is percentage of map

u8g2.sendBuffer();
}
void C1_pinky(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(49, 32, "PINKY");

u8g2.drawFrame(2,0,17,17);
u8g2.drawStr(8,2, "1");

u8g2.drawFrame(23,0,17,17);
u8g2.drawStr(29,2, "2");

u8g2.drawFrame(44,0,17,17);
u8g2.drawStr(50,2, "3");

u8g2.drawFrame(65,0,17,17);
u8g2.drawStr(71,2, "4");

u8g2.drawBox(86,0,17,17);   //Selected box
u8g2.drawStr(92,2, "5");    //Selected string

u8g2.drawFrame(107,0,17,17);
u8g2.drawStr(113,2, "6");

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

#define pinkyMin 13
#define pinkyMax 161
uint8_t pinky_angle=13;
uint8_t pinky_percentage=0;

void C1_pinky_in(void){
jky_servo_movement();
btn_Jky(4);
if(movement==1 && pinky_angle<pinkyMax){
pinky_angle++;
}
else if(movement==2 && pinky_angle>pinkyMin){
pinky_angle--;
}
setServo(4,pinky_angle);
pinky_percentage=map(pinky_angle, pinkyMin, pinkyMax, 0, 100);
String percentage = String(pinky_percentage);

u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(12,24, "Pinky:");
u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
u8g2.drawStr(82,24, "%");

u8g2.drawFrame(12,40,102,17);
u8g2.drawBox(13,41,middle_percentage,15);   //x is percentage of map

u8g2.sendBuffer();
}
void C1_wrist(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(49, 32, "WRIST");

u8g2.drawFrame(2,0,17,17);
u8g2.drawStr(8,2, "1");

u8g2.drawFrame(23,0,17,17);
u8g2.drawStr(29,2, "2");

u8g2.drawFrame(44,0,17,17);
u8g2.drawStr(50,2, "3");

u8g2.drawFrame(65,0,17,17);
u8g2.drawStr(71,2, "4");

u8g2.drawFrame(86,0,17,17);
u8g2.drawStr(92,2, "5");

u8g2.drawBox(107,0,17,17);    //Selected box
u8g2.drawStr(113,2, "6");     //Selected string

u8g2.drawFrame(115,51,12,10);
u8g2.drawXBMP(117, 53, 8, 6, back);

u8g2.sendBuffer();
}

#define wristMin 180
#define wristMax 150
uint8_t wrist_angle=180;
uint8_t wrist_percentage=0;

void C1_wrist_in(void){
jky_servo_movement();
btn_Jky(4);
if(movement==1 && wrist_angle>wristMax){
wrist_angle--;
}
else if(movement==2 && wrist_angle<wristMin){
wrist_angle++;
}
setServo(5,wrist_angle);
wrist_percentage=map(wrist_angle, wristMin, wristMax, 0, 100);
String percentage = String(wrist_percentage);

u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(12,24, "Wrist:");
u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
u8g2.drawStr(82,24, "%");

u8g2.drawFrame(12,40,102,17);
u8g2.drawBox(13,41,wrist_percentage,15);   //x is percentage of map

u8g2.sendBuffer();
}
void C1_goBack(void){
u8g2.clearBuffer();
u8g2.setDrawColor(2);

u8g2.drawStr(43, 32, "GO BACK");

u8g2.drawFrame(2,0,17,17);
u8g2.drawStr(8,2, "1");

u8g2.drawFrame(23,0,17,17);
u8g2.drawStr(29,2, "2");

u8g2.drawFrame(44,0,17,17);
u8g2.drawStr(50,2, "3");

u8g2.drawFrame(65,0,17,17);
u8g2.drawStr(71,2, "4");

u8g2.drawFrame(86,0,17,17);
u8g2.drawStr(92,2, "5");

u8g2.drawFrame(107,0,17,17);
u8g2.drawStr(113,2, "6");

u8g2.drawBox(115,51,12,10);   //Selected box

u8g2.setDrawColor(0);
u8g2.drawXBMP(117, 53, 8, 6, back);
u8g2.sendBuffer();
}

//MAIN CUSTOM METHOD
void custom_C1(void){
switch(C1){
case thumb:
if(swbtn_state==5){
jky_servo_movement();
C1_thumb_in();
}
else{
btn_Jky(5);
jkyC1();
C1_thumb();  //print on display F1_rock
}
break;

case index:
if(swbtn_state==5){ //s'ha de canviar!!
C1_index_in();
}
else{
btn_Jky(5);
jkyC1();
C1_index();  //print on display F1_rock
}
break;

case middle:
if(swbtn_state==5){ //s'ha de canviar!!
C1_middle_in();
}
else{
btn_Jky(5);
jkyC1();
C1_middle();  //print on display F1_rock
}
break;

case ring:
if(swbtn_state==5){ //s'ha de canviar!!
C1_ring_in();
}
else{
btn_Jky(5);
jkyC1();
C1_ring();  //print on display F1_rock
}
break;

case pinky:
if(swbtn_state==5){ //s'ha de canviar!!
C1_pinky_in();
}
else{
btn_Jky(5);
jkyC1();
C1_pinky();  //print on display F1_rock
}
break;

case wrist:
if(swbtn_state==5){ //s'ha de canviar!!
C1_wrist_in();
}
else{
btn_Jky(5);
jkyC1();
C1_wrist();  //print on display F1_rock
}
break;

case goBackC1:
btn_Jky(0);
jkyC1();
C1_goBack();  //print on display F1_rock
break;
}
}

void setup(){
u8g2.begin();
u8g2_prepare();
servo.begin();
servo.setPWMFreq(Freq);
pinMode(jky, INPUT_PULLUP);
F1=rock;
C1=thumb;
M1=openClose;
swbtn_state=0;
}

void loop(){
modes_M1();
}
import numpy as np
p = np.array([1/2, 1/2])
ex = np.array([1, 2])
dot_prod = ex @ p
cout<<name;
#ifdef __APPLE__
freopen("inputFilename.txt", "r", stdin);
freopen("outputFilename.txt", "w", stdout);
#endif
Part 1:

void func(); // Declares func()

// File1.cc
void func() {   // Defines func()
...
}

// File2.cc
...  // Do something else
func(); // Calls func()

Part 2:

inline void func() { // Defines func()
...
}

// File2.cc
... // Do something else
... // Code for func()
bool operator<(const Person &other) const {
if (name == other.name) {
return age < other.age;
} else {
return name < other.name;
}
}

//This fixes the problem: In template: invalid operands to binary     expression ('const Person' and 'const Person')
std::string test1 = "Baked";
std::string test2 = "Bake";
bool compare = test1 < test2;

// Output: 0
/* Reason: There is no difference until the last letter so then it will compare the last letter with the blank space.
Since blank space comes first before the letter d, this means that test1 is not less than test2 and that is why it returns false.*/

std::string test1 = "Baker";
std::string test2 = "Bdke";
bool compare = test1 < test2;

// Output: 1
/* Reason: There is no difference until the second letter so then it will compare the second letter with the second letter of the other word.
Since the letter a comes first before the letter d, this means that test1 is less than test2 and that is why it returns true.*/
Example:

people = Person(3, "Bob");
people = Person(4, "Joe");
people = Person(5, "Sue");

Example 2:

people.insert(std::pair <int, Person> (0, Person(3, "Bob")));
people.insert(std::pair <int, Person> (1, Person(4, "Joe")));
people.insert(std::pair <int, Person> (2, Person(5, "Sue")));
#include <iostream>

using namespace std;

struct student
{
int age;
};

int main() {
student steve;		//variable
student *ken;		//ken is a pointer.  It points to the memory address which holds the ken struct.

steve.age = 7;
ken->age = 9;

return;
}
#include <iostream>

using namespace std;

int main(){

cout << "Hello World";

return 0;
}
std::exception <exception> interface (debatable if you should catch this)
std::bad_alloc <new> failure to allocate storage
std::bad_cast <typeinfo> execution of an invalid dynamic-cast
std::bad_exception <exception> signifies an incorrect exception was thrown
std::bad_function_call <functional> thrown by "null" std::function
std::bad_typeid <typeinfo> using typeinfo on a null pointer
std::logic_error <stdexcept> errors detectable before the program executes
std::domain_error <stdexcept> parameter outside the valid range
std::future_error <future> violated a std::promise/std::future condition
std::invalid_argument <stdexcept> invalid argument
std::length_error <stdexcept> length exceeds its maximum allowable size
std::out_of_range <stdexcept> argument value not in its expected range
std::runtime_error <stdexcept> errors detectable when the program executes
std::overflow_error <stdexcept> arithmetic overflow error.
std::underflow_error <stdexcept> arithmetic underflow error.
std::range_error <stdexcept> range errors in internal computations
std::regex_error <regex> errors from the regular expression library.
std::system_error <system_error> from operating system or other C API
std::ios_base::failure <ios> Input or output error
int gcdYisLargerThanX(int x, int y)
{
return x==0 ? y : gcd(y%x, x);
}
bool isPrime(int n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;

// This is checked so that we can skip
// middle five numbers in below loop
// any integer can be expressed as (6k + i), where i = -1, 0, 1, 2, 3, 4
// (6k + 0), (6k + 2), (6k + 4) covered by n%2
// (6k + 3) covered by n%3
if (n % 2 == 0 || n % 3 == 0)
return false;

// Check for 6K + 1 and 6K - 1
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;

return true;
}
int maxSubArray(vector<int>& nums) {
int maxSum = nums, currSum = nums;

for(int i=1; i < nums.size(); i++)
{
currSum += nums[i];
if(nums[i] > currSum) currSum = nums[i];
maxSum = (currSum > maxSum) ? currSum : maxSum;
}
return maxSum;
}
int maxProduct(vector<int>& nums) {
int32_t res=nums;

for(int32_t i=1, min=res, max = res; i < nums.size(); i++)
{
if(nums[i] < 0)
swap(min, max);
max = std::max(nums[i] * max, nums[i]);
min = std::min(nums[i] * min, nums[i]);
res = std::max(res, max);
}
return res;
}
#include<bits/stdc++.h>

using namespace std;
//Implement the class Box
//l,b,h are integers representing the dimensions of the box

// The class should have the following functions :

// Constructors:
// Box();
// Box(int,int,int);
// Box(Box);

// int getLength(); // Return box's length
// int getHeight ();  //Return box's height
// long long CalculateVolume(); // Return the volume of the box

//bool operator<(Box& b)

//ostream& operator<<(ostream& out, Box& B)
class Box {
private:
int length;
int height;

public:
Box() {
this->length = 0;
this->height = 0;
}

Box(int l, int b, int h) {
this->length = l;
this->height = h;
}
};

void check2()
{
int n;
cin>>n;
Box temp;
for(int i=0;i<n;i++)
{
int type;
cin>>type;
if(type ==1)
{
cout<<temp<<endl;
}
if(type == 2)
{
int l,b,h;
cin>>l>>b>>h;
Box NewBox(l,b,h);
temp=NewBox;
cout<<temp<<endl;
}
if(type==3)
{
int l,b,h;
cin>>l>>b>>h;
Box NewBox(l,b,h);
if(NewBox<temp)
{
cout<<"Lesser\n";
}
else
{
cout<<"Greater\n";
}
}
if(type==4)
{
cout<<temp.CalculateVolume()<<endl;
}
if(type==5)
{
Box NewBox(temp);
cout<<NewBox<<endl;
}

}
}

int main()
{
check2();
}
int main(){
// Initialization of list
std::list<int> demo_list;

// Assigning the value 100, 5 times
// to the list, list_demo.
demo_list.assign(5, 100);

// Displaying the list
for (int itr : demo_list) {
std::cout << itr << " ";
}

return 0;
}
#pragma once
#ifndef MYVEC_H
#define MYVEC_H
#include <iostream>
#include<algorithm>

template <typename T>
class Myvec
{
public:
Myvec();
Myvec(int& size);
Myvec(int& size, T& value);
~Myvec();
void push_back(T& value);
void pop();
unsigned int get_size()const;
T at(int& index)const;
bool empty()const;
void clear();
void swap(Myvec& v);
void print();
private:
T* elements;
int size;
int capacity;
void ensureCapacity();
};
template<typename T>
Myvec<T>::Myvec():size(0),capacity(16)
{
elements = new T[capacity];
}
template<typename T>
Myvec<T>::Myvec(int& size)
{
size = size;
}
template<typename T>
Myvec<T>::Myvec(int& size, T& vlaue)
{
size = size;
elements = vlaue;
}
template<typename T>
Myvec<T>::~Myvec()
{
delete[] elements;
}
template<typename T>
void Myvec<T>::push_back(T& value)
{
ensureCapacity();
elements[size++] = value;
}
template < typename T>
void Myvec<T>::ensureCapacity()
{
if (size >= capacity)
{
T* old = elements;
capacity = 2 * size;
elements = new T[size * 2];

for (int i = 0; i < size; i++)
elements[i] = old[i];

delete[] old;
}
}
template <typename T>
void Myvec<T>::pop()
{
--size;
}
template <typename T>
unsigned int Myvec<T>::get_size()const
{
return size;
}
template <typename T >
T Myvec<T>::at(int& index)const
{
if(index < size)
return elements[index];
}
template <typename T>
bool Myvec<T>::empty()const
{
return size == 0;
}
template <typename T>
void Myvec<T>::clear()
{
size = 0;
}
template <typename T>
void Myvec<T>::swap(Myvec& v)
{

T* temp = new T[size];
int s = this->size;
for (int i = 0; i < s; i++)
{
temp[i] =this->elements[i];
}

this->clear();
for (int i = 0; i < v.get_size(); i++)
{
this->push_back(v.elements[i]);
}
v.clear();
for (int i = 0; i < s; i++)
{
v.push_back(temp[i]);
}

delete[]temp;
}
template<typename T>
void Myvec<T>::print()
{
for (int i = 0; i < size; i++)
{
std::cout << this->at(i)<<" ";
}
std::cout << std::endl;
}
#endif // !MYVEC_H

#include <iostream>
#include <vector>
#include <string>
#include"Stack.h"
#include<algorithm>
#include "Myvec.h"

using namespace std;

int main()
{
Myvec<int> v1;
Myvec<int> v2;
for (int i = 1; i < 50; i++)
{
v2.push_back(i);
}
for (int i = 0; i < 20; i++)
{
v1.push_back(i);
}

v1.print();
cout << endl;
}
#include <iostream>
#include <string>
using namespace std;
#define ll long long

int main()
{
srand(time(0));
const int SIZE = 10;
string words[SIZE] = { "skinny","skinny","three","arrange",
"discussion", "squeeze" ,"flowers","credit","matter","visit"};
int random = rand() % SIZE;
string s = words[random];
string astrid_word("");

astrid_word = s;
for (int i = 0; i < astrid_word.length(); i++)
{
astrid_word[i] = '*';
}
char guess;
int tries = 1;
bool youWin = false;
int miss = 0;
while ( tries <= 20)
{
int flag = 0;
cout << tries<<" enter your guess " << astrid_word<<" ";
cin >> guess;
for (int i = 0; i < astrid_word.length(); i++)
{
if (s.at(i) == guess)
{
if (s.at(i) == astrid_word.at(i))
{
cout <<"   "<< guess << " is already in the word\n";
}
else
{
astrid_word.at(i) = guess;
flag = 1;
}
}
}
if (flag == 0)
miss++;
if (astrid_word == s)
{
youWin = true;
cout << "the word is " << astrid_word<<endl;
break;
}
tries++;
}
if (youWin == true)
{
cout << " -------------------------------- \n";
cout << "|                                |\n";
cout << "|                                |\n";
cout << "|   (:CONGRATULATIONS YOU WIN(:  |\n";
cout << "|                                |\n";
cout << "|                                |\n";
cout << " -------------------------------- \n";
cout << "you tried " << tries << " times \n";
cout << "you miss " << miss << " time\n";

}
else
{
cout << "the word is " << s << "): you loose ):";
}

}

#include <iostream>

#include <string>
using namespace std;
#define ll long long

int intOfEnd(string& s)
{
int start = s.find("ATG");
int end1 = s.find("TAG", start);
int end2 = s.find("TAA", start);
int end3 = s.find("TGA", start);

int list = { end1,end2,end3 };
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (list[i] < list[j] && list[i] != string::npos)
return list[i];
}
}

for (int i = 0; i < 3; i++)
{
if (list[i] != string::npos)
return list[i];
}
return 0;

}
int main()
{
string s;
cin >> s;

string ans("");
int l = 0;

for (int j = 0; j < s.length(); j++)
{
int start = s.find("ATG");
if ((start != string::npos && intOfEnd(s) != 0))
{
for (int i = start + 3; i < intOfEnd(s); i++)
{
ans += s[i];
}
cout << "gene "<<ans << endl;

s.erase(start, 6);
ans.clear();
l++;
}

}
if (l == 0)
cout << "no gene found ";
}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
#include <vector>

using namespace std;

bool  isConsecutiveFour(char grid[]) {

// checking rows
for (int i = 0; i < 6; i++)
{
char current = grid[i];
int rowCnsec = 0;
for (int j = 0; j < 7; j++)
{
if (current == grid[i][j] && grid[i][j] != ' ')
{
rowCnsec++;
if (rowCnsec == 4) return true;
}
else
{
current = grid[i][j];
rowCnsec = 1;
}
}
}
// check columns
for (int j = 0; j < 7; j++)
{
char current = grid[j];
int colConsec = 0;
for (int i = 0; i < 6; i++)
{
if (current == grid[i][j] && grid[i][j] != ' ')
{
colConsec++;
if (colConsec == 4) return true;
}
else
{
current = grid[i][j];
colConsec = 1;
}
}
}

// check top Left side: going upright
for (int i = 5; i >= 0 ; i--)
{
int consecutive = 0;
int y = i;
int x = 0;
char current = grid[y][x];
while (y >= 0)
{
if (grid[y][x] == current && grid[y][x] != ' ')
{
consecutive++;
if (consecutive == 4) return true;
}
else
{
consecutive = 1;
current = grid[y][x];
}
x++;
y--;
}

}
// check bottom right side: going upright
for (int j = 0; j < 7; j++) {
int y = 6 - 1;
int x = j;
int consecutive = 0;
int current = grid[y][x];

while (x < 6 && y >= 0) {

if (grid[y][x] == current && grid[y][x] != ' ') {
consecutive++;
if (consecutive == 4) return true;
}
else {
consecutive = 1;
current = grid[y][x];
}
x++;
y--;
}

}

// check bottom left side going up-left
for (int j = 7 - 1; j > 0; j--) {

int x = j;
int y = 6 - 1;
int current = grid[y][x];
int consecutiveCount = 0;

while (x >= 0 && y >= 0) {

if (grid[y][x] == current && grid[y][x] != ' ') {
consecutiveCount++;
if (consecutiveCount == 4) return true;
}
else {
consecutiveCount = 1;
current = grid[y][x];
}

x--;
y--;
}
}
// check bottom right side going up-left
for (int row = 1; row < 6; row++) {
int x = 7 - 1;
int y = row;
int consecutive = 0;
int current = grid[y][x];

while (y >= 0) {

if (grid[y][x] == current && grid[y][x] != ' ') {
consecutive++;
if (consecutive == 4) return true;
}
else {
consecutive = 1;
current = grid[y][x];
}
x--;
y--;
}
}
return false;
}
// a function to show the grid
void show_grid(char grid[])
{

for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 7; j++)
{
cout << "|" << grid[i][j];
}
cout << "|" << endl;
}
}

void player1(char grid[], int x, int y)
{
show_grid(grid);

cout << "Drop a red disk at column (0–6): ";
cin >> y;
if (grid[x][y] == ' ')
grid[x][y] = 'R';
else {
//make sure not to target the same row
while (grid[x][y] != ' ')x--;
grid[x][y] = 'R';
}
}

void player2(char grid[],int x,int y)
{
show_grid(grid);

cout << "Drop a yellow disk at column (0–6): ";
cin >> y;
if (grid[x][y] == ' ')
grid[x][y] = 'Y';
else {
//make sure not to target the same row
while (grid[x][y] != ' ')x--;
grid[x][y] = 'Y';
}

}
//check if it's a draw
bool is_draw(char grid[])
{
for (int i = 0; i < 7; i++)
{
int count{0};
if (grid[i] != ' ' && grid[i] != ' ' && grid[i] != ' '
&& grid[i] != ' ' && grid[i] != ' ' && grid[i] != ' ')
count++;
if(count == 6)
return true;
return false;
}
}
int main()
{
char grid;
//fill the grid with blank space
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 7; j++)
{
grid[i][j] = ' ';
}
}
//to check the winner
bool winner1 = false;
bool winner2 = false;

while (!is_draw(grid))
{
int x{ 5 };
int y{ 0 };
player1(grid, x, y);
if (isConsecutiveFour(grid))
{
winner1 = true;
break;
}
player2(grid, x, y);
if (isConsecutiveFour(grid))
{
winner2 = true;
break;
}
}
show_grid(grid);
if (winner1 == true)
cout << "player 1 wins ";
else if (winner2 == true)
cout << "player 2 wins ";
else
cout << "It's a draw ";

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

bool  isConsecutiveFour(int values[]) {

// checking rows
for (int i = 0; i < 6; i++) {

int current = values[i];
int consecutiveCount = 0; // values[i] starts count

for (int j = 0; j < 7; j++) {

if (values[i][j] == current) {
consecutiveCount++;
if (consecutiveCount == 4) return true;
}
else {
current = values[i][j];
consecutiveCount = 1;
}
}
}
// check columns
for (int j = 0; j < 7; j++) {

int consecutiveCount = 0; // values[j] starts count
int current = values[j];

for (int i = 0; i < 6; i++) {

if (values[i][j] == current) {
consecutiveCount++;
if (consecutiveCount == 4) return true;
}
else {
current = values[i][j];
consecutiveCount = 1;
}

}
}

// check topLeft side: going upright
for (int i = 6 - 1; i > 0; i--) {
int y = i;
int x = 0;
int consecutive = 0;
int current = values[y][x];

while (y >= 0) {

if (values[y][x] == current) {
consecutive++;
if (consecutive == 4) return true;
}
else {
consecutive = 1;
current = values[y][x];
}
x++;
y--;
}
}

// check bottom right side: going upright
for (int j = 0; j < 7; j++) {
int y = 6 - 1;
int x = j;
int consecutive = 0;
int current = values[y][x];

while (x < 6 && y >= 0) {

if (values[y][x] == current) {
consecutive++;
if (consecutive == 4) return true;
}
else {
consecutive = 1;
current = values[y][x];
}
x++;
y--;
}

}

// check bottom left side going up-left
for (int j = 7 - 1; j > 0; j--) {

int x = j;
int y = 6 - 1;
int current = values[y][x];
int consecutiveCount = 0;

while (x >= 0 && y >= 0) {

if (values[y][x] == current) {
consecutiveCount++;
if (consecutiveCount == 4) return true;
}
else {
consecutiveCount = 1;
current = values[y][x];
}

x--;
y--;
}
}
// check bottom right side going up-left
for (int row = 1; row < 6; row++) {
int x = 7 - 1;
int y = row;
int consecutive = 0;
int current = values[y][x];

while (y >= 0) {

if (values[y][x] == current) {
consecutive++;
if (consecutive == 4) return true;
}
else {
consecutive = 1;
current = values[y][x];
}
x--;
y--;
}

}
return false;
}

// Driver code
int main()
{
int m;
for (int i = 0; i < 6; i++)
for (int j = 0; j < 7; j++)
cin >> m[i][j];
if (isConsecutiveFour(m) == true)
cout << "true";
else
cout << "false";

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

void decToBinary(int n)
{
// array to store binary number
int binaryNum;

//converting to binary
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
binaryNum[i][j] = n % 2;
n = n / 2;

}
}

// printing binary> array in reverse order
for (int i = 3-1; i >= 0; i--){
for (int j = 3 - 1; j >= 0; j--)
{
if (binaryNum[i][j] == 0)
cout << "H" << " ";
else
cout << "T" << " ";
}
cout << endl;
}

}

int main()
{
int n;
cout << "Enter a decimal number between 1 and 512 ";
cin >> n;

decToBinary(n);
return 0;
}

//(Financial application: compute tax) Rewrite Listing 3.3, ComputeTax.cpp,
//using arrays. For each filing status, there are six tax rates. Each rate is applied
//to a certain amount of taxable income. For example, from the taxable income
//of \$400,000 for a single filer, \$8,350 is taxed at 10%, (33,950–8,350) at 15%,
//(82,250–33,950) at 25%, (171,550–82,550) at 28%, (372,550–82,250) at
//33%, and (400,000–372,950) at 36%. The six rates are the same for all filing
//statuses, which can be represented in the following array:
//double rates[] = {0.10, 0.15, 0.25, 0.28, 0.33, 0.36};
//The brackets for each rate for all the filing statuses can be represented in a twodimensional array as follows:
//i//nt brackets =
//{
// {8350, 33950, 82250, 171550, 372950}, // Single filer
// //{16700, 67900, 137050, 20885, 372950}, // Married jointly
// or qualifying
// widow(er)
// {8350, 33950, 68525, 104425, 186475}, // Married separately
// {11950, 45500, 117450, 190200, 372950} // Head of household
//};
//Suppose the taxable income is \$400,000 for single filers. The tax can be computed
//as follows:
//tax = brackets * rates +
// (brackets – brackets) * rates +
//(brackets – brackets) * rates +
// (brackets – brackets) * rates +
// (brackets – brackets) * rates +
// (400000 – brackets) * rates

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

double computeTax(int brackets[], double rates[],
int status, double income);
int getStatus();

// Driver code
int main()
{
double rates[] = { 0.10, 0.15, 0.25, 0.28, 0.33, 0.36 };

int brackets =
{
{8350, 33950, 82250, 171550, 372950}, // Single filer
{16700, 67900, 137050, 20885, 372950}, // Married jointly
// or qualifying
// widow(er)
{8350, 33950, 68525, 104425, 186475}, // Married separately
{11950, 45500, 117450, 190200, 372950} // Head of household
};

cout << "(1-single filer, 2-married jointly, "
<< "or qualifying widow(er), " << endl
<< "3-married separately, 4-head of household)" << endl
<< "Enter the filing status: ";
int status = getStatus();
cout<< "Enter the taxable income: ";
double income;
cin >> income;
cout << "The tax for your income " << income << " is " << computeTax(brackets, rates, status, income);
}

double computeTax(int brackets[], double rates[],
int status, double income) {
double tax = 0, incomeTaxed = 0;
for (int i = 4; i >= 0; i--) {
if (income > brackets[status][i])
tax += (incomeTaxed = income - brackets[status][i]) * rates[i + 1];
income -= incomeTaxed;
}
return tax += brackets[status] * rates;
}
int getStatus() {

int status;
do {
cin >> status;
if (status < 0 || status > 3)
cout<<"Error: invalid status";
} while (status < 0 || status > 3);
return status;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

void sortRowWise(int m[],
int r, int c)
{
// loop for rows of matrix
for (int i = 0; i < r; i++)
{
// loop for column of matrix
for (int j = 0; j < c; j++)
{
// loop for comparison and swapping
for (int k = 0; k < c - j - 1; k++)
{
if (m[i][k] > m[i][k + 1])
{
// swapping of elements
swap(m[i][k], m[i][k + 1]);
}
}
}
}

// printing the sorted matrix
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
cout << m[i][j] << " ";
cout << endl;
}
}

// Driver code
int main()
{
int m;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cin >> m[i][j];
}
}
int r = sizeof(m) / sizeof(m);
int c = sizeof(m) / sizeof(m);
sortRowWise(m, r, c);
return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);
int bin2Dec(int binNumber);
int dec2octal(const string& number);

bool isValid(const int grid[]);
bool isValid(int i, int j, const int grid[]);

int main()
{
int grid;

cout << (isValid(grid) ? "Valid solution" : "Invalid solution");

return 0;
system("pause");
}

// Read a Sudoku puzzle from the keyboard
{
cout << "Enter a Sudoku puzzle:" << endl;
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
cin >> grid[i][j];
}
bool isValid(const int grid[])
{
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
if (grid[i][j] < 1 || grid[i][j] > 9 ||
!isValid(i, j, grid))
return false;

return true; // The fixed cells are valid
}

// Check whether grid[i][j] is valid in the grid
bool isValid(int i, int j, const int grid[])
{
// Check whether grid[i][j] is valid at the i's row
for (int column = 0; column < 9; column++)
if (column != j && grid[i][column] == grid[i][j])
return false;

// Check whether grid[i][j] is valid at the j's column
for (int row = 0; row < 9; row++)
if (row != i && grid[row][j] == grid[i][j])
return false;

// Check whether grid[i][j] is valid in the 3-by-3 box
for (int row = (i / 3) * 3; row < (i / 3) * 3 + 3; row++)
for (int col = (j / 3) * 3; col < (j / 3) * 3 + 3; col++)
if (row != i && col != j && grid[row][col] == grid[i][j])
return false;

return true; // The current value at grid[i][j] is valid
}
USTRUCT()
struct FMapRow {
GENERATED_BODY()

UPROPERTY()
TArray<int8> Columns;

FORCEINLINE int8& operator[] (int32 j)
{
return Columns[j];
}

void SetGridBase(int8 Block, int32 y)
{
Columns[y] = Block;
}

{
}

FMapRow()
{

}
};

USTRUCT()
struct FMapLayer {
GENERATED_BODY()

UPROPERTY()
TArray<FMapRow> Rows;

FORCEINLINE FMapRow& operator[] (int32 i)
{
return Rows[i];
}

{
}

void AddUninitialized(const int32 RowCount, const int32 ColCount)
{
Clear();
for (int32 v = 0; v < RowCount; v++)
{
}

for (int32 v = 0; v < RowCount; v++)
{
for (int32 b = 0; b < ColCount; b++)
{
}
}
}

void Clear()
{
if (Rows.Num() <= 0) return;
//~~~~~~~~~~~~~~~

//Destroy any Actors
const int32 RowTotal = Rows.Num();
const int32 ColTotal = Rows.Columns.Num();

//Empty
for (int32 v = 0; v < Rows.Num(); v++)
{
Rows[v].Columns.Empty();
}
Rows.Empty();
}

TTuple<int32, int32> NumLayerDimensions()
{
return TTuple<int32, int32>(Rows.Num(), Rows.Columns.Num());
}

//default properties
FMapLayer()
{

}

FMapLayer(int32 Rows, int32 Cols)
{
}
};

USTRUCT()
struct FMapSector {
GENERATED_BODY()

UPROPERTY()
TArray<FMapLayer> Layers;

FORCEINLINE FMapLayer& operator[] (int32 i)
{
return Layers[i];
}

{
}

void AddUnitialized(int32 LayerCount, int32 RowCount, int32 ColCount)
{
Clear();
for (int32 l = 0; l < LayerCount; l++)
{
}

for (int32 l = 0; l < LayerCount; l++)
{
for (int32 r = 0; r < RowCount; r++)
{
}
}

for (int32 l = 0; l < LayerCount; l++)
{
for (int32 r = 0; r < RowCount; r++)
{
for (int32 c = 0; c < ColCount; c++)
{
}
}
}
}

void Clear()
{
if (Layers.Num() <= 0) return;
//~~~~~~~~~~~~~~~

//Destroy any Actors
const int32 LayerTotal = Layers.Num();
const int32 RowTotal = Layers.Rows.Num();
const int32 ColTotal = Layers.Rows.Columns.Num();

//Empty
for (int32 l = 0; l < LayerTotal; l++)
{
for (int32 r = 0; r < RowTotal; r++)
{
Layers[l].Rows[r].Columns.Empty();
}
}
for (int32 l = 0; l < LayerTotal; l++)
{
Layers[l].Rows.Empty();
}

Layers.Empty();
}

FMapSector()
{
}

FMapSector(int32 size)
{
}

FMapSector(int32 Layers, int32 Rows, int32 Cols)
{
}
};
#include <iostream>
#include<iomanip>
#include <string>

using namespace std;

void partisons(int list[], int listSize);

int main()
{
const int size1 = 6;

int list1[size1];
for (int i = 0; i <size1 ; i++)
{
cin >> list1[i];
}
selectionSort(list1, size1);

for (int i = 0; i < size1; i++)
{
cout << list1[i] << " ";
}

}

void partisons(int list[], int listSize)
{
int first = 0;
int low = first + 1;
int high = listSize - 1;
int pivot = list[first];

while (high > low) {

while (low <= high && list[low] <= pivot)
{
low++;
}
while (low <= high && list[high] > pivot)
{
high--;
}
if (high > low) {
int temp = list[high];
list[high] = list[low];
list[low] = temp;
}
}

while (high >= low && list[high] >= pivot) high--;

if (high > first) {
int temp = list[high];
list[high] = list[first];
list[first] = temp;

}

}

#include<iostream>
using namespace std;

int sum(int arr[], int a);

int main() {
int arr, n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
cout << sum(arr, n);
}
}
int sum(int arr[], int a) {
int i;
sum = 0;
for (i=0; i<n; ++i) {
sum += arr[i];
}
return sum;
}#include<iostream>
using namespace std;

int sum(int arr[], int a);

int main() {
int arr, n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
cout << sum(arr, n);
}
}
int sum(int arr[], int a) {
int i;
sum = 0;
for (i=0; i<n; ++i) {
sum += arr[i];
}
return sum;
}
"For Loop": {
"prefix": "for",
"body": [
"for (var \${index} = 0; \${index} < \${array}.length; \${index}++) {",
"\tvar \${element} = \${array}[\${index}];",
"\t\$0",
"}"
],
"description": "For Loop"
},
#include <iostream>
#include<iomanip>

using namespace std;
void eightQueens(char board[], int size);
void shuffle(char list[], int size);
int linearSearch(char list[], char key, int arraySize);
int linearSearchInt(int list[], int key, int arraySize);

const int SIZE = 8;
int main()
{	char board[SIZE];

srand(unsigned( time(0)));
int x = rand()%SIZE;
for (int i = 0; i < SIZE; i++)
{
if (i == x)
board[i] = 'Q';
else
board[i] = ' ';
}
eightQueens(board, SIZE);
}
void eightQueens(char board[],int size)
{
int count = 0, vale, test[SIZE];
for (int i = 0; i < size ; i++)
{
vale = linearSearch(board, 'Q', size);
bool flage = true;

for (int j = 0; j < count;j++)
{
if (test[j] == vale)
flage = false;
}
if (flage == true)
{
for (int j = 0; j < size; j++)
{
cout  << "|";
cout << board[j];
}
test[count] = vale;
count++;
shuffle(board, size);
}
else
{
int n = 0;
for (int j = 0; j < 100; j++)
{
shuffle(board, size);
if (linearSearchInt(test, linearSearch(board, 'Q', size), size) == -1)
{
n = linearSearch(board, 'Q', size);
test[count] = n;
count++;
break;
}
}
for (int j = 0; j < SIZE; j++)
{
if (j == n)
board[j] = 'Q';
else
board[j] = ' ';
}
for (int j = 0; j < size; j++)
{
cout << "|";
cout << board[j] ;
}

}
cout <<'|'<< endl;
}

}

int linearSearch( char list[], char key, int arraySize)
{
for (int i = 0; i < arraySize; i++)
{
if (key == list[i])
return i;
}
return -1;
}
int linearSearchInt(int list[], int key, int arraySize)
{
for (int i = 0; i < arraySize; i++)
{
if (key == list[i])
return i;
}
return -1;
}
void shuffle(char list[], int size)
{

for (int i = size - 1; i > 0; i--)
{
// Generate an index j randomly with 0 <= j <=i
int j = rand() % (i + 1);
// Swap myList[i] with myList[j]
char temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}

int list[LIMIT], i, j, val, count, flag, test[LIMIT], c = 0;
//enter the values
for (i = 0; i < LIMIT; i++)
{
cout << "Enter The Elements : ";
cin >> list[i];
if (list[i] == 0)
break;
}
//count the occurence of each value
for (j = 0; j < LIMIT; j++)
{
count = 0;
flag = 1;
val = list[j];
//counts each value's occurence and if the value is 0 break
for (i = 0; i < LIMIT; i++)
{
if (val == list[i])
count++;
else if (list[i] == 0)
break;
}
//checks whether the value has been already counted (flag = 0) or not (flag stays 1)
for (i = 0; i < c; i++)
{
if (test[i] == val)
flag = 0;
}
//if the value has not been counted print
if (flag == 1)
{

cout << "The Occurence Of The Number " << val << " is " << count << endl;
test[c] = val;
c++;
}

}
#include<iostream>
#include <fstream>
#include <cctype>
#include<ctffunc.h>
using namespace std;

void enterLetters(char list[], int limit);
void countVandCLetters(char list[], int limit);

const int LIMIT = 100;

int main()
{
char letters[LIMIT];

enterLetters(letters, LIMIT);
countVandCLetters(letters, LIMIT);

}
void enterLetters(char list[], int limit)
{

for (int i = 0; i < limit; i++)
{
cin >> list[i];
if (list[i] == '0')
break;
}
}
void countVandCLetters(char list[], int limit)
{
int vowel = 0;
int Consonant = 0;
char vowels[] = { 'a','e','o','u','i' };
char Consonants[] = { 'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z' };

for (int i = 0; i < limit; i++)
{
if (IsCharUpperA(list[i]))
list[i] = list[i] + 32;

for (int j = 0; j < 5; j++)
{
if (list[i] == vowels[j])
vowel++;
}
for (int j = 0; j < 21; j++)
{

if (list[i] == Consonants[j])
Consonant++;
}

}

cout << "Number Of vowels Letters is " << vowel << endl;
cout << "Number Of Consonants Letters is " << Consonant << endl;

}

#include<iostream>
#include <fstream>
using namespace std;
void selectionSort(double list[], int listSize);
int main()
{
double list[] = { 3.4, 5, 3, 3.5, 2.2, 1.9, 2 };

selectionSort(list, 7);
for (int i = 0; i < 7; i++)
{
cout << list[i]<<" ";
}
}
//decreasing order
void selectionSort(double list[], int listSize)
{
for (int i = listSize-1; i >= 0 ; i--)
{
double currentMax = list[i];
int currentMaxIndex = i;
for (int j = i - 1; j >= 0; j--)
{
if (currentMax < list[j])
{
currentMax = list[j];
currentMaxIndex = j;
}
}
if (currentMaxIndex != i)
{
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}

}
}
//increasing order
void selectionSort(double list[], int listSize)
{
for (int i = 0; i < listSize - 1; i++)
{
double currentMin = list[i];
int currentMinIndex = i;
for (int j = i + 1; j < listSize; j++)
{
if (currentMin > list[j])
{
currentMin = list[j];
currentMinIndex = j;
}
}
if (currentMinIndex != i)
{
list[currentMinIndex] = list[i];
list[i] = currentMin;
}

}
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
ll cs=0;
ll tab;
void spar(ll a[],ll n)
{
ll i,j;
for(i=0;i<n;i++)
tab[i]=a[i];
for(j=1;(1<<j)<=n;j++)
{
for(i=0;i+(1<<(j-1))-1<n;i++)
tab[i][j]=__gcd(tab[i][j-1],tab[i+(1<<(j-1))][j-1]);
}
}
ll qry(ll a,ll b)
{
ll j=log2(b-a+1);
return __gcd(tab[a][j],tab[b-(1<<j)+1][j]);
}
void sol()
{
ll n,m,i,sum=0;
cin>>n>>m;
ll a[n];
for(i=0;i<n;i++)
cin>>a[i];
spar(a,n);
for(i=0;i+m-1<n;i++)
sum+=qry(i,i+m-1);
cout<<sum;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ll t;
//cin>>t;
//while(t--)
sol();
return 0;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
ll cs=0;
struct duo
{
ld x,F,S;
};
bool sim(duo a,duo b)
{
if(a.F==b.F||a.F==b.S||a.S==b.F||a.S==b.S)
return 1;
return 0;
}
void sol()
{
cout.precision(11);
cout<<fixed;
ll n,i,k;
cin>>n;
ld a[n],vl,ans=0;
duo low,h;
for(i=0; i<3; i++)
low[i].x=INT_MAX;
for(i=0; i<n; i++)
cin>>a[i];
sort(a,a+n);
for(i=0; i<3; i++)
{
h[i].F=a[n-1-i];
h[i].S=a[n-2-i];
}
for(i=0; i<n-1; i++)
{
vl=abs(a[i]-a[i+1]);
for(k=0; k<3; k++)
{
if(vl<low[k].x)
{
ll j=k;
for(j=2; j>=k+1; j--)
{
low[j].x=low[j-1].x;
low[j].F=low[j-1].F;
low[j].S=low[j-1].S;
}
low[k].x=vl;
low[k].F=a[i];
low[k].S=a[i+1];
break;
}
}
}
for(i=0;i<3;i++)
{
for(k=0;k<3;k++)
{
if(!sim(h[i],low[k]))
ans=fmax(ans,(h[i].F+h[i].S)/low[k].x);
}
}
cout<<ans;

}
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
//ll t;
//cin>>t;
//while(t--)
sol();
return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
// CPP program to check if a string is
// substring of other.

using namespace std;

// Returns true if s1 is substring of s2
int isSubstring(string s1, string s2)
{
int M = s1.length();
int N = s2.length();

/* A loop to slide pat[] one by one */
for (int i = 0; i <= N - M; i++) {
int j;

/* For current index i, check for
pattern match */
for (j = 0; j < M; j++)
if (s2[i + j] != s1[j])
break;

if (j == M)
return i;
}

return -1;
}

/* Driver program to test above function */
int main()
{
string s1 ,s2 ;
getline(cin, s1);
getline(cin, s2);
int res = isSubstring(s1, s2);
if (res == -1)
cout << "Not present";
else
cout << "Present at index " << res;
return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);
int bin2Dec(int binNumber);
int dec2octal(const string& number);

int main()
{
string binNumber;
getline(cin, binNumber);
cout << dec2octal(binNumber);
return 0;
}
int dec2octal(const string& number)
{
int binNumber = stringToNum(number);
int decimalNumber = bin2Dec(binNumber);
int octal = 0, placeValue = 1;
while (decimalNumber != 0)
{
octal += (decimalNumber % 8) * placeValue;
decimalNumber /= 8;
placeValue *= 10;
}
return octal;
}

int bin2Dec(int binNumber)
{
int digits, decimal = 0, count = 0, bin = binNumber;
while (bin != 0)
{
digits = bin % 10;
decimal += digits* pow(2,count);

bin /= 10;
count++;

}
return decimal;
}
int stringToNum(string binNumber)
{
int convertedNumber = 0;
for (int i = 0; i < binNumber.length(); i++)
{

convertedNumber = (convertedNumber * 10) + static_cast<int>(binNumber[i] - '0');
}
return convertedNumber;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);

int main()
{
string number;
getline (cin , number);

cout << octal2Dec(number);
return 0;
}

int octal2Dec(string& octal)
{
int digits, decimal = 0, count = 0,oct = stringToNum(octal);
while (oct != 0)
{

digits = oct % 10;
if(validity(digits) == true)
decimal += digits* pow(8,count);
else
{
return NAN;
}
oct /= 10;
count++;

}
return decimal;
}
bool validity(int number)
{
return number % 8 == 0 || number % 9 == 0? false : true;

}
int stringToNum(string number)
{
int convertedNumber = 0;
for (int i = 0; i < number.length(); i++)
{
convertedNumber = (convertedNumber * 10) + static_cast<int>(number[i] - '0');
}
return convertedNumber;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

string format(int number, int width);
int numberWidthF(int number);

int main()
{

int number,width;
cin >> number >> width;
cout << format(number, width);

}
string format(int number, int width)
{
string zeros = " ";
string num = to_string(number);

int numberWidth = numberWidthF(number);

for (int  i = 1; i <= width-numberWidth; i++)
{
zeros += "0";
}
return zeros+num;
}
int numberWidthF(int number)
{
int digits, numberWidth = 0;
while (number != 0)
{
digits = number % 10;
number /= 10;
numberWidth++;
}
return numberWidth;
}
cout << "Machine ID: ";
//WHILE LOOP: check whether Machine ID is in numeric
while(!(cin >> machineID)){
//display error message
cout << "ERROR! Invalid Machine ID! Please try again..." << endl;
cout << "Machine ID: ";

cin.clear(); //clear previous user input
cin.ignore(INT_MAX, '\n'); //discard previous user input
}
//
//			case 1:
//				break;
//
//			case 2:
//				retrieveJob(h, j);
//				break;
//
//			case 3:
//				cout << "Option 3..." << endl;
//				break;
//
//			case 4:
//				cout << "Option 4..." << endl;
//				break;
//
//			case 5:
//				cout << "Bye!";
//				exit(0); //terminate program
//				break;
//
//			default:
//				cout << "ERROR! Invalid option! Please try again..." << endl;
//				break;
//		}
//
//	}

cout << "Please enter number to select: ";

//error check
while(!cin.good()){
//report problem when user input in not numeric
cout << "ERROR! Faulty input! Please try again..." << endl;

//clear stream
cin.clear();
cin.ignore(INT_MAX, '\n');

//get input again
cout << "Please enter number to select: ";
}

//clear stream
cin.clear();
cin.ignore(INT_MAX, '\n');

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

double avgOfEvenPlaces(int number);
int reversal(int n);

int main()
{

int number;
cin >> number;
cout << fixed<<setprecision(3)<<avgOfEvenPlaces(reversal(number));
}
double  avgOfEvenPlaces(int n)
{

int digit, count = 1.0, countOfEven = 0.0;
double sumOfEven = 0.0;
while (n != 0)
{
digit = n % 10;
n /= 10;

if (count % 2 == 0)
{

sumOfEven += digit;
countOfEven++;
}
count++;
}

return  sumOfEven / countOfEven;

}
int reversal(int n)
{
int digits, revers = 0.0;
while (n != 0)
{
digits = n % 10;
revers = revers * 10 + digits;
n /= 10;
}
return revers;
}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

double sqrt(int n);

int main()
{

long n;
cin >> n;
cout << "the approximated sqrt of the number " << n << " is " << sqrt(n);
}
double sqrt(long n)
{
double lastGuess = 1;
double nextGuess = (lastGuess + n / lastGuess) / 2;

while (nextGuess - lastGuess > 0.0001)
{
nextGuess = lastGuess;
(lastGuess + (n / lastGuess)) / 2;
}
lastGuess = nextGuess;
return nextGuess = (lastGuess + n / lastGuess) / 2;

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int sumOfDigits(int n);

int main()
{

int count = 0;
int number = 13;
cout << setw(3) << "Prime number" << setw(20) << "Sum of its digits" << endl;
for (int i = 2; i <= 70; i++)
{
cout <<setw(1)<< i<<setw(15)<<sumOfDigits(i)<<endl;
}

}

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0) {

return false;
}
}
return true;
}

{

return true;
else
return false;
}
int sumOfDigits(int n)
{
int sum = 0, digit = 0;
while (n != 0)
{
digit = n % 10;
sum += digit;
n /= 10;
}
return sum;
}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

bool Emirp(int n);
int reversal(int n);
int recursive(int a, int b);

int main()
{

int count = 0;
int number = 13;
while (count <= 100)
{
if (Emirp(number))
{
count++;
if (count % 10 == 0)
cout << setw(7) << number << endl;
else
cout << setw(7) << number;
}
number++;
}

}

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0) {

return false;
}
}
return true;
}

bool Emirp(int n) {

}

int reversal(int n) {

if (n < 10) {

return n;

}
return recursive(n % 10, n / 10);

}

int recursive(int a, int b) {

if (b < 1) {

return a;

}
return recursive(a * 10 + b % 10, b / 10);

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;
bool isEven(int number);
bool isPalindrom(int number);

int main()
{

int count = 0, number = 1;

while (count <= 50)
{

if(isEven(number) == true && isPalindrom(number) == true)
{
count++;
if (count % 5 == 0)
cout << setw(8) << number << endl;
else
cout << setw(8) << number;
}
number++;
}

}

bool isEven(int number)
{
if (number % 2 == 0)
return true;
else
return false;

}
bool isPalindrom(int number)
{
int reverse = 0, rem = 0;
int num = number;
while (number != 0)
{
rem = number % 10;
reverse = reverse * 10 + rem;
number /= 10;
}
if (reverse == num)
return true;
else
return false;
}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

bool isArmstrong(int n);
int reversNumber(int n);
void isReversedArmstrong(int n);

int main()
{
cout << "Enter first integer: ";
int n1;
cin >> n1;
isReversedArmstrong(n1);

}

bool isArmstrong(int n)
{
int temp = 0,armstrong, total = 0;
armstrong = n;
while (armstrong != 0)
{
temp = armstrong % 10;
total += pow(temp, 3);
armstrong /= 10;
}
if (total == n)
return true;
else
return false;
}
int reversNumber(int n)
{
int reverse = 0, rem = 0;
while (n != 0)
{
rem = n % 10;
reverse = reverse * 10 + rem;
n /= 10;
}
return reverse;
}
void isReversedArmstrong(int n)
{
if (isArmstrong(n))
{
if(isArmstrong(reversNumber(n)))
cout << "the Reversed "<< reversNumber(n)<<" number IS an Armstrong number ";
else
cout << "the Reversed " << reversNumber(n) << " number is NOT Armstrong number ";
}
else
cout << "the number entered is NOT Armstrong number ";

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int LCM(int n1, int n2);

int main()
{
cout << "Enter first integer: ";
int n1;
cin >> n1;

cout << "Enter second integer: ";
int n2;
cin >> n2;

cout << "Least Common Multiple for " << n1 <<
" and " << n2 << " is " << LCM(n1,n2)<< endl;
}

int LCM(int n1, int n2)
{
int lcm = 1;
int max = (n1 > n2) ? n1 : n2;

while (true)
{
if (max % n1 ==0 && max % n2 == 0)
{
lcm = max;
break;
}
else
max++;

}

return lcm; // Return gcd
}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int compute_profit(int quantity);

int main()
{
int quantity = 1000;
cout << "Quantity " << setw(9) << "Profit-per-item (in \$)"<<endl;
for ( ; quantity <= 10000; quantity+=1000)
{
cout<<quantity<< setw(9)<<compute_profit(quantity)<<endl;
}

}
int compute_profit(int quantity)
{
int profit = 0;

if (quantity < 1000)
profit += quantity; // * 1
else
{
profit += 1000;
quantity -= 1000;
if (quantity < 4000)
profit += quantity * 2;
else
{
profit += 8000; // 4000 * 2
quantity -= 4000;
profit += quantity * 5;
}
}

return profit;
}

// access v1 by copy
[v1]() {
for (auto p = v1.begin(); p != v1.end(); p++) {
cout << *p << " ";
}
};
/**
SHAMI AL BASHAR PROTHOY
PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
vi<ll>coins;
struct tim
{
ll s,f;
};
bool cmp(tim a,tim b)
{
if(a.s!=b.s)return a.s<b.s;
return a.f<b.f;
}
/**
THINK TWICE,
CODE ONCE
**/

void sol(ll cs)
{
ll n,i,sum=1,j;
cin>>n;
tim t;
vector<tim>v;
for(i=0;i<n;i++)
cin>>t.f>>t.s,v.pb(t);
sort(v.B,v.E,cmp);//if time ain't sorted
j=0;
for(ll i=1;i<n;i++)
{
if(v[i].f>=v[j].s)sum++,j=i;
}
cout<<sum<<"\n";
}
//CODE
int main()
{
//freopen("inp.txt","r",stdin)
scanf("%lld",&T);
while(T--)
sol(cs++);
return 0;
}
/**
SHAMI AL BASHAR PROTHOY
PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
struct pt
{
ll x,y,t;
};
/**
THINK TWICE,
CODE ONCE
**/
void show(vi<ll>&v)
{
for(auto it:v)cout<<it<<' ';
cout<<"\n";
}
vi<ll> filsub(vi<ll>v)
{
vi<ll>temp;
ll i,j,n=v.size(),sum;
for(i=0;i<(1<<n);i++)
{
sum=0;
for(j=0;j<n;j++)
{
if(i&(1<<j))
sum+=v[j];
}
temp.pb(sum);
}
return temp;
}
void sol(ll cs)
{
vi<ll>v,va,vb;
ll n,i,a,k;
cin>>n>>k;
for(i=0;i<n;i++)cin>>a,v.pb(a);
va.assign(v.B,v.E-n/2);
vb.assign(v.B+(n+1)/2,v.E);
sort(va.B,va.E);
sort(vb.B,vb.E);
va=filsub(va);
vb=filsub(vb);
bool bl=false;
for(i=0;i<va.size();i++)
{
if(binary_search(vb.B,vb.E,k-va[i]))
{
bl=true;
break;
}
}
cout<<csee<<((bl)?"Yes":"No")<<"\n";
}
//CODE
int main()
{
//freopen("inp.txt","r",stdin)
scanf("%lld",&T);
while(T--)
sol(cs++);
return 0;
}
/**
SHAMI AL BASHAR PROTHOY
PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
struct pt
{
ll x,y,t;
};
/**
THINK TWICE,
CODE ONCE
**/
void show(vi<ll>&v)
{
for(auto it:v)cout<<it<<' ';
cout<<"\n";
}
set<ll> filsub(vi<ll>v)
{
set<ll>temp;
ll i,j,n=v.size(),sum;
for(i=0;i<(1<<n);i++)
{
sum=0;
for(j=0;j<n;j++)
{
if(i&(1<<j))
sum+=v[j];
}
temp.ins(sum);
}
return temp;
}
void sol(ll cs)
{
set<ll>sa,sb;
vi<ll>v,va,vb;
ll n,i,a,k;
cin>>n>>k;
for(i=0;i<n;i++)cin>>a,v.pb(a);
va.assign(v.B,v.E-n/2);
vb.assign(v.B+(n+1)/2,v.E);
sort(va.B,va.E);
sort(vb.B,vb.E);
sa=filsub(va);
sb=filsub(vb);
bool bl=false;
for(auto it=sa.B;it!=sa.E;it++)
{
if(sb.count(k-*it))
{
bl=true;
break;
}
}
cout<<csee<<((bl)?"Yes":"No")<<"\n";
}
//CODE
int main()
{
//freopen("inp.txt","r",stdin)
scanf("%lld",&T);
while(T--)
sol(cs++);
return 0;
}
/**
SHAMI AL BASHAR PROTHOY
PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
const ld pi=2*acos(0.0);
ll T,N;
ll cs=1;
ll soln=0;
/**
THINK TWICE,
CODE ONCE
**/
bool ok(vi<vi<ll>>&v,ll row,ll col)
{
if(row>=0&&row<N&&col>=0&&col<N&&!v[row][col])
return true;
return false;
}
void go(vi<vi<ll>>&v,ll row,ll col,ll tp)
{
if(row==N-1&&col==N-1)
{
if(N*N==tp)
soln++;
return;
}
v[row][col]=1;
if(row==0&&col==0)
go(v,row+1,col,tp+1);
else
{
v[row][col]=0;
bool l=false,r=false,u=false,d=false;
if(ok(v,row,col+1))
r=true;
if(ok(v,row,col-1))
l=true;
if(ok(v,row+1,col))
d=true;
if(ok(v,row-1,col))
u=true;
if(!u&&!d&&r&&l)
return;
if(u&&d&&!r&&!l)
return;
v[row][col]=1;
if(r)
go(v,row,col+1,tp+1);
if(l)
go(v,row,col-1,tp+1);
if(d)
go(v,row+1,col,tp+1);
if(u)
go(v,row-1,col,tp+1);
}
v[row][col]=0;
}
void sol(ll cs)
{
soln=0;
cin>>N;
vi<ll>temp(N,0);
vi<vi<ll>>v(N,temp);
go(v,0,0,1);
cout<<csee<<2*soln<<"\n";
}
//CODE
int main()
{
//freopen("inp.txt","r",stdin)
scanf("%lld",&T);
while(T--)
sol(cs++);
return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

void printMonth(int year, int month);
void printMonthTitle(int year, int month);
void ptintMonthName(int month);
void printMonthBody(int year, int month);
int getStartDay(int year, int month);
int getTotalNumberOfDays(int year, int month);
int getNumberOfDaysInMonth(int year, int month);
bool isLeapYear(int year);

int main()
{
cout << "Enter full year ";
int year;
cin >> year;
cout << " Enter month in number between 1 and 12: ";
int month;
cin >> month;
printMonth(year, month);

}
void printMonth(int year, int month)
{
printMonthTitle(year, month);

printMonthBody(year, month);
}

void printMonthTitle(int year, int month)

{
ptintMonthName(month);
cout << " " << year << endl;
cout << "-----------------------------" << endl;
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;

}

void ptintMonthName(int month)

{
switch (month)
{
case 1:
cout << "January";
break;
case 2:
cout << "February";
break;
case 3:
cout << "March";
break;
case 4:
cout << "April";
break;
case 5:
cout << "May";
break;
case 6:
cout << "June";
break;
case 7:
cout << "July";
break;
case 8:
cout << "August";
break;
case 9:
cout << "September";
break;
case 10:
cout << "October";
break;
case 11:
cout << "November";
break;
case 12:
cout << "December";
}
}
void printMonthBody(int year, int month)
{
int startDay = getStartDay(year, month);
int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);

for (int i = 0; i < startDay; i++)
cout << "    ";
for (int i = 1; i <=  numberOfDaysInMonth; i++)
{
cout << setw(4) << i;
if ((i + startDay) % 7 == 0)
cout << endl;
}
}
int getStartDay(int year, int month)
{
int startDay1800 = 3;
int totalNumberOfDays = getTotalNumberOfDays(year, month);

return (totalNumberOfDays + startDay1800) % 7;

}
int getTotalNumberOfDays(int year, int month)
{
int total = 0;
for (int i = 1800; i < year; i++)
{
if (isLeapYear(i))
total += 366;
else
total += 365;
}
for (int i = 1; i < month; i++)
{
total += getNumberOfDaysInMonth(year, i);
}
}
int getNumberOfDaysInMonth(int year, int month)
{
if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;

if (month == 2) return isLeapYear(year) ? 29 : 28;

return 0;
}
bool  isLeapYear(int year)
{
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int hexDec(const string& hex);
int hexCharToDecimal(char ch);
int main()
{
cout << "enter a hex Number ";
string hex;
cin >> hex;

cout << "The Decimal Number For Hex Is  " << hex
<< " is " << hexDec(hex) << endl;
}
int hexDec(const string&  hex)
{
int decimalValue = 0;
for (unsigned i = 0; i < hex.length(); i++)
{
decimalValue = decimalValue * 16 + hexCharToDecimal(hex[i]);
}
return decimalValue;

}
int hexCharToDecimal(char ch)
{
ch = toupper(ch);
if (ch >= 'A' && ch <= 'F')
return 10 + ch - 'A';
else
return ch - '0';
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
int counter = 1;
int number = 0;
int largest = 0;
int n;
cin >> n;
int occurrence = 0;

cout << "Please enter up to 10 numbers and I will print the largest one on the screen.\n\n";

while (counter <= n)
{
cout << "Number: ";
cin >> number;

if (largest < number)
{
largest = number;
occurrence = 1;

}
else if (number == largest)
{
occurrence++;
}
if (number == 0)
{
break;

}
counter++;
}

cout << "the largest number is "<<largest << endl;
cout << "  the occurrence count " << largest << " is " << occurrence << " time";

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

int firstprofit = 0;
int quantity = 0;
int q3 = 1;

//the targeted profit >> 50000
cout << "Enter the profit ";
int endProfit;
cin >> endProfit;

//first five quantity 1 * 1000+2 * 4000
firstprofit += 9000;
do
{
//the remaining quantity(q3) which is 50000(endProfit) - 9000(firstProfit) / 5
if (q3 == (endProfit - 9000) / 5)

firstprofit += q3 * 5;
else
q3++;

} while (firstprofit <= endProfit);

//the whole quantity
quantity += 1000 + 4000 + q3;

cout << quantity;

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
int num, reversedInteger = 0, remainder, originalInteger;
cin >> num;
originalInteger = num;
for (; num != 0; num /= 10)
{
remainder = num % 10;
reversedInteger = reversedInteger * 10 + remainder;
}

if (originalInteger == reversedInteger)
cout << originalInteger << " is a palindrome.";
else
cout << originalInteger << " is not a palindrome.";

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

int f1 = 0, f2 = 1;
int nextTerm = 0;
for (int i = 1; i < 10; i++)
{
//print first 2 numbers
if (i == 1)
{
cout <<  f1<<" ";
continue;
}
if (i == 2)
{
cout << f2 << " ";
continue;
}

nextTerm = f1 + f2;
f1 = f2;
//make f2 = the next term
f2 = nextTerm;
cout << nextTerm<<" ";

}

}

5 8
1 4 6 8 12 15 16 18
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
cout << "enter the year ";
int year;
cin >> year;

cout << "Enter The First Day Of The year ";
int FirstDay;
cin >> FirstDay;
int count = 1;
int days = 1;
for (int month = 1; month <= 12; month++)
{
cout << "             ";
switch (month)
{
case 1: cout << "January " << year<<endl;
break;
case 2: cout << "February " << year << endl;
break;
case 3: cout << "March  " << year << endl;
break;
case 4: cout << "April  " << year << endl;
break;
case 5: cout << "May " << year << endl;
break;
case 6: cout << "June  " << year << endl;
break;
case 7: cout << "July  " << year << endl;
break;
case 8: cout << "August " << year << endl;
break;
case 9: cout << "September " << year << endl;
break;
case 10: cout << "October " << year << endl;
break;
case 11: cout << "November " << year << endl;
break;
case 12: cout << "December " << year << endl;
break;
}
cout << " --------------------------------------------------------- "<<endl;
cout << "  Sun Mon Tue Wed Thu Fri Sat"<<endl;
for (int i = 0; i < FirstDay; i++)
{
cout << "    ";
}
for (int i = 1; i < 31; i++)
{
if (i < 10) {
cout<<"   " <<i;
}
else {
cout<<"  " << i;
}
if ((i + FirstDay) % 7 == 0) {
cout << endl;
}
}
cout << endl;

FirstDay = (FirstDay + 31) % 7;

}

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
cout << "enter the month ";
int month;
cin >> month;
cout << "Enter The First Day Of The Month ";
int firstDay;
cin >> firstDay;
int nextSunday = 1;

switch (firstDay)
{

case 1: nextSunday += 7;
cout << "The first day of this month is sunday "<<endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7 ;
}
break;

case 2: nextSunday += 6;
cout << "The first day of this month is monday " << endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7;
}
break;
case 3: nextSunday += 5;
cout << "The first day of this month is tuesday " << endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7;
}
break;
case 4: nextSunday += 4;
cout << "The first day of this month is wednesday " << endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7;
}
break;
case 5: nextSunday += 3;
cout << "The first dayof this month is thursday " << endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7;
}
break;
case 6: nextSunday += 2;
cout << "The first day of this month is friday " << endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7;
}
break;
case 7: nextSunday += 1;
cout << "The first day of this month is saturday " << endl;
while (nextSunday < 30)
{
cout << "Next Sunday of this month is on " << nextSunday << endl;
nextSunday += 7;
}
break;

}

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
int number;
cin >> number;
for (int i = 0; i <=number; i++)
{
for (int j = 0; j <= number; j++)
{
if
(
i == 0 || i == number ||
i == number/2|| j == number/2||
j == 0 || j == number ||
i == j || j == (number - i + 0)
)
cout <<" "<< "*";
else
cout << "  ";
int h = (number - i + 1);
}

cout << "\n";
}

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
for (int i = 0; i < 8; i++)
{
for (int k = 0; k <= i; k++)
{
cout << "  ";
}
for (int j = i; j < 8; j++)
{
cout <<" "<< static_cast<char>(j+97-i);

}
for (int j = 7; j >= i; j--)
{
cout << " " << static_cast<char>(j + 97 - i);
}
cout << "\n";
}

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

cout << " ##############";
cout << endl;
for (int  i = 0; i <=5; i++)
{

for (int j = 0;  j < 1;  j++)
{
cout << " " << "#";
}
for (int j = 1;  j <= i;  j++)
{
cout << " ";
}
for (int j = 0; j <1; j++)
{
cout << "#";
}
for (int j = i; j < 5; j++)
{
cout << " ";
}
for (int j = i; j < 5; j++)
{
cout << " ";

}
for (int j = 0; j <1 ; j++)
{
cout << "#";
}
for (int j = 0; j < i; j++)
{
cout << " ";
}
for (int i = 0; i < 1; i++)
{
cout << "#";
}
cout << endl;
}

for (int i = 0; i <=5; i++)
{
for (int j = 0; j < 1; j++)
{
cout << " " << "#";
}
for (int j = 5; j >i; j--)
{
cout << " ";
}
for (int j = 0;  j< 1; j++)
{
cout << "#";
}
for (int j = 0; j < i; j++)
{
cout << " ";
}
for (int j = 0; j < i; j++)
{
cout << " ";
}
for (int j = 0; j < 1; j++)
{
cout << "#";
}
for (int j = 5; j > i ; j--)
{
cout << " ";
}
for (int i = 0; i < 1; i++)
{
cout << "#";
}
cout << endl;

}
cout << " ##############";
cout << endl;

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

int rows;
cin >> rows;

for (int i = 1; i <= rows; i++)
{
for (int k = 1; k <= (rows -i); k++)
{
cout << "   ";

}
for (int d = i; d > 1; d--)
{
cout << d << "  ";

}
for (int  v = 1; v <= i; v++)
{
cout << v<<"  ";
}
cout << endl;

}

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
int firstLetter = 65;
int count = 0;

for (int i = 65; i <= 90; i++)
{
count++;
if (count%5 == 0)
cout << setw(3) << static_cast<char>(i) << endl;
else
cout << setw(3) << static_cast<char>(i);

}

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

cout << "Enter two positive numbers ";
int n1,n2;
cin >> n1>>n2;
int d = 1;
int gcd = 1;

if (n1 < n2)
d = n1;
else
d = n2;
while (true)
{
if (n1 % d == 0 && n2 % d == 0) {
gcd = d;
break;
}

d--;
}

cout << "the CGD of " << n1 << " and " << n2 << " is " << gcd;

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

int n = 1;
int largest = 0;
while (n*n<30000)
{
if (n > largest)
{
largest = n;
}
n++;
}
cout << "the largest number is " << largest;

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

int count = 0;

// iterate from 0 to N
for (int num = 300,count = 0; num <=400; num++)
{
// Short-circuit operator is used
if (num % 3 == 0 || num % 6 == 0)
{
cout << setw(5) << num;
count++;
if (count % 5 == 0)
cout << setw(5) << num << endl;

}

}

}
#include <iostream>
using namespace std;
int main()
{
int n1=0,n2=1,n3,i,number;
cout<<"Enter the number of elements: ";
cin>>number;
cout<<n1<<" "<<n2<<" "; //printing 0 and 1
for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
cout<<n3<<" ";
n1=n2;
n2=n3;
}
return 0;
}
#include<iostream>
using namespace std;

int main()
{
cout<<"Enter the integers: "<
}
include <FirebaseArduino.h>

#define FIREBASE_HOST "example.firebaseio.com"
#define FIREBASE_AUTH "token_or_secret"

void setup() {
Serial.begin(9600);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

int n = 0;

void loop() {

// set value
Firebase.setFloat("number", 42.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);

// update value
Firebase.setFloat("number", 43.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);

// get value
Serial.print("number: ");
Serial.println(Firebase.getFloat("number"));
delay(1000);

// remove value
Firebase.remove("number");
delay(1000);

// set string value
Firebase.setString("message", "hello world");
// handle error
if (Firebase.failed()) {
Serial.print("setting /message failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);

// set bool value
Firebase.setBool("truth", false);
// handle error
if (Firebase.failed()) {
Serial.print("setting /truth failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);

// append a new value to /logs
String name = Firebase.pushInt("logs", n++);
// handle error
if (Firebase.failed()) {
Serial.print("pushing /logs failed:");
Serial.println(Firebase.error());
return;
}
Serial.print("pushed: /logs/");
Serial.println(name);
delay(1000);
}

#include <ESP8266WiFi.h>

// Set these to run example.
#define WIFI_SSID "SSID"

// connect to wifi.
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
#include <stdio.h>

class Node
{
public:
Node( int v )
{
data = v;
left = 0;
right = 0;
}

int data;
Node* left;
Node* right;
};

void Add( Node** root, Node* n )
{
if ( !*root  )
{
*root = n;
return;
}

if ( (*root)->data < n->data )
{
}
else
{
}
}

void Print( Node* node )
{
if ( !node )  return;
Print( node->left );
printf( "value = %i\n", node->data );
Print( node->right );
}

int main()
{
Node* root = 0;

Add( &root, new Node( 1 ) );
Add( &root, new Node( 2 ) );
Add( &root, new Node( -1 ) );
Add( &root, new Node( 12 ) );

Print( root );
return 0;
}
int maxSubArraySum(int a[], int size)
{
int max_so_far = 0, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_ending_here < 0)
max_ending_here = 0;

/* Do not compare for all elements. Compare only
when max_ending_here > 0 */
else if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
}
return max_so_far;
}
// Define macros for inlining x86 assembly in a compiler-independent way
#ifdef _MSC_VER
#define ASM1(asm_literal) \
__asm asm_literal
#define ASM2(asm_literal1, asm_literal2) \
__asm asm_literal1, asm_literal2
#define ASM3(asm_literal1, asm_literal2, asm_literal3) \
__asm asm_literal1, asm_literal2, asm_literal3

#define ASM_MOV_REG_VAR(register, variable) \
ASM(mov register, variable)

#define ASM_MOV_VAR_REG(variable, register) \
ASM(mov variable, register)

#elif __GNUC__ || __clang__
#define ASM1(asm_literal) \
ASM_GCC(#asm_literal)
#define ASM2(asm_literal1, asm_literal2) \
ASM_GCC(#asm_literal1 ", " #asm_literal2)
#define ASM3(asm_literal1, asm_literal2, asm_literal3) \
ASM_GCC(#asm_literal1 ", " #asm_literal2 ", " #asm_literal3)

#ifdef __x86_64__
#define ASM_MOV_REG_VAR(register, variable) \
__asm__ __volatile__("movq %0, %%" EXPAND_AND_QUOTE(register)  : /* no outputs */ : "m"(variable) : )

#define ASM_MOV_VAR_REG(variable, register) \
__asm__ __volatile__("movq %%" EXPAND_AND_QUOTE(register) ", %0"  : "=m"(variable) : /* no inputs */ : )
#else
#define ASM_MOV_REG_VAR(register, variable) \
__asm__ __volatile__("mov %0, %%" EXPAND_AND_QUOTE(register)  : /* no outputs */ : "m"(variable) : )

#define ASM_MOV_VAR_REG(variable, register) \
__asm__ __volatile__("mov %%" EXPAND_AND_QUOTE(register) ", %0"  : "=m"(variable) : /* no inputs */ : )
#endif

#define ASM_GCC(asm_string) \
__asm__ __volatile__(".intel_syntax noprefix;" asm_string ";.att_syntax prefix"); \

#endif
#include<iostream>                //including input/output libarary
using namespace std;
int main(){                               //starting main function
int array_name;                   //defining a variable array of type integer with name "array_name" and size 5.
array_name=2;                   //assigning value of 2 to  first element of array "array_name"
array_name=3;
array_name=4                      // assinging values to other elements of array using their index number
array_name=12;
array_name=33;

return 0;
}
> More steps
star

Sun Jan 23 2022 04:44:32 GMT+0000 (UTC)

#c++
star

Tue Jan 18 2022 03:26:32 GMT+0000 (UTC) https://stackoverflow.com/questions/5029840/convert-char-to-int-in-c-and-c

#c++
star

Thu Jan 13 2022 18:47:14 GMT+0000 (UTC)

#c++
star

Tue Jan 11 2022 16:05:38 GMT+0000 (UTC) https://www.geeksforgeeks.org/binary-search/

#c++
star

Sun Jan 09 2022 14:21:05 GMT+0000 (UTC) https://www.codewars.com/kata/53da3dbb4a5168369a0000fe/train/cpp

#c++
star

Sun Jan 09 2022 14:09:41 GMT+0000 (UTC) https://www.hackerrank.com/challenges/c-tutorial-basic-data-types/problem

#c++
star

Sun Jan 09 2022 14:04:55 GMT+0000 (UTC) https://www.hackerrank.com/challenges/c-tutorial-pointer/problem?h_r=profile

#c++
star

Sun Jan 09 2022 11:48:11 GMT+0000 (UTC)

#c++
star

Sun Jan 09 2022 09:49:36 GMT+0000 (UTC)

#c++
star

Sat Jan 08 2022 15:00:06 GMT+0000 (UTC)

#c++
star

Sat Jan 08 2022 09:14:50 GMT+0000 (UTC)

#c++
star

Mon Dec 27 2021 06:01:57 GMT+0000 (UTC)

#c++
star

Tue Dec 14 2021 12:08:47 GMT+0000 (UTC)

#c++
star

Tue Dec 14 2021 11:27:30 GMT+0000 (UTC)

#c++
star

Tue Dec 14 2021 11:17:42 GMT+0000 (UTC)

#c++
star

Tue Dec 14 2021 08:21:19 GMT+0000 (UTC)

#c++
star

Tue Dec 14 2021 07:55:04 GMT+0000 (UTC)

#c++
star

Mon Dec 13 2021 11:06:15 GMT+0000 (UTC)

#c++
star

Mon Dec 13 2021 09:35:05 GMT+0000 (UTC)

#c++
star

Mon Dec 13 2021 09:30:14 GMT+0000 (UTC)

#c++
star

Sun Dec 12 2021 13:09:05 GMT+0000 (UTC)

#c++
star

Sun Dec 12 2021 08:16:59 GMT+0000 (UTC)

#c++
star

Sun Dec 12 2021 07:49:39 GMT+0000 (UTC)

#c++
star

Sun Dec 12 2021 07:45:54 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 16:53:50 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 16:12:33 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 15:36:10 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 11:38:23 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 10:01:09 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 07:19:07 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 07:05:18 GMT+0000 (UTC)

#c++
star

Fri Dec 10 2021 04:09:27 GMT+0000 (UTC)

#c++
star

Thu Dec 09 2021 18:27:36 GMT+0000 (UTC)

#c++
star

Thu Dec 09 2021 17:22:41 GMT+0000 (UTC)

#c++
star

Thu Dec 09 2021 14:02:47 GMT+0000 (UTC)

#c++
star

Thu Dec 09 2021 09:27:14 GMT+0000 (UTC)

#c++
star

Thu Dec 09 2021 06:51:51 GMT+0000 (UTC)

#c++
star

Thu Dec 09 2021 05:32:57 GMT+0000 (UTC)

#c++
star

Wed Dec 08 2021 17:13:49 GMT+0000 (UTC)

#c++
star

Wed Dec 08 2021 15:12:25 GMT+0000 (UTC)

#c++
star

Fri Dec 03 2021 08:22:07 GMT+0000 (UTC) https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array

#c++
star

Thu Nov 18 2021 11:00:12 GMT+0000 (UTC) https://favtutor.com/blogs/reverse-a-linked-list-cpp

#c++
star

Wed Nov 17 2021 07:53:08 GMT+0000 (UTC) https://sgo.tomedu.ru/angular/school/studentdiary/

#java #c++
star

Mon Oct 25 2021 13:57:16 GMT+0000 (UTC)

#c #c++
star

Mon Oct 25 2021 12:19:03 GMT+0000 (UTC)

#c++
star

Sun Oct 10 2021 07:54:16 GMT+0000 (UTC)

#c++
star

Thu Oct 07 2021 11:43:56 GMT+0000 (UTC) https://leetcode.com/problems/reshape-the-matrix/

#c++
star

Wed Oct 06 2021 08:57:16 GMT+0000 (UTC) https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

#c++
star

Wed Oct 06 2021 08:11:28 GMT+0000 (UTC) https://leetcode.com/problems/intersection-of-two-arrays-ii/submissions/

#c++
star

Wed Oct 06 2021 07:45:46 GMT+0000 (UTC) https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/

#c++
star

Wed Oct 06 2021 07:37:13 GMT+0000 (UTC) https://leetcode.com/problems/move-zeroes/

#c++
star

Tue Oct 05 2021 12:13:11 GMT+0000 (UTC) https://leetcode.com/problems/rotate-array/

#c++
star

Tue Oct 05 2021 11:18:54 GMT+0000 (UTC) https://leetcode.com/problems/squares-of-a-sorted-array/

#c++
star

Mon Oct 04 2021 12:09:28 GMT+0000 (UTC) https://leetcode.com/problems/contains-duplicate/

#c++
star

Mon Oct 04 2021 10:24:48 GMT+0000 (UTC) https://leetcode.com/problems/merge-sorted-array/

#c++
star

Mon Oct 04 2021 09:30:38 GMT+0000 (UTC) https://leetcode.com/problems/plus-one/

#c++
star

Mon Oct 04 2021 08:26:09 GMT+0000 (UTC) https://leetcode.com/problems/maximum-subarray/

#c++
star

Mon Oct 04 2021 08:06:18 GMT+0000 (UTC) https://leetcode.com/problems/search-insert-position/

#c++
star

Mon Oct 04 2021 07:37:20 GMT+0000 (UTC) https://leetcode.com/problems/remove-element/

#c++
star

Sat Oct 02 2021 18:08:51 GMT+0000 (UTC)

#c++
star

Tue Sep 07 2021 09:04:19 GMT+0000 (UTC)

#c++
star

Sun Sep 05 2021 18:21:30 GMT+0000 (UTC)

#c #c++
star

Sun Sep 05 2021 18:20:03 GMT+0000 (UTC)

#c #c++
star

Sun Sep 05 2021 18:12:07 GMT+0000 (UTC)

#c #c++
star

Thu Sep 02 2021 08:48:00 GMT+0000 (UTC)

#c++
star

Thu Sep 02 2021 07:14:28 GMT+0000 (UTC)

#c++
star

Thu Sep 02 2021 06:44:36 GMT+0000 (UTC)

#c++
star

Mon Aug 30 2021 07:18:58 GMT+0000 (UTC)

#c++
star

Mon Aug 30 2021 01:00:16 GMT+0000 (UTC)

#c #c++
star

Sat Aug 28 2021 16:20:48 GMT+0000 (UTC)

#c++
star

Wed Aug 18 2021 18:16:33 GMT+0000 (UTC)

#c++
star

Fri Aug 13 2021 04:11:57 GMT+0000 (UTC)

#c++
star

Thu Aug 12 2021 09:38:38 GMT+0000 (UTC) https://leetcode.com/problems/palindrome-number/

#c++
star

Thu Aug 12 2021 08:50:25 GMT+0000 (UTC) https://leetcode.com/problems/reverse-integer/

#c++
star

Thu Aug 12 2021 08:48:54 GMT+0000 (UTC) https://leetcode.com/problems/two-sum/submissions/

#c++
star

Thu Jul 08 2021 07:53:58 GMT+0000 (UTC) https://pastebin.com/YfYcJ5f1

#c++
star

Fri Jul 02 2021 18:33:06 GMT+0000 (UTC)

#c++
star

Fri Jul 02 2021 17:34:27 GMT+0000 (UTC)

#c++
star

Fri Jul 02 2021 08:16:57 GMT+0000 (UTC) https://leetcode.com/explore/challenge/card/july-leetcoding-challenge-2021/608/week-1-july-1st-july-7th/3800/

#c++
star

Wed Jun 23 2021 05:09:08 GMT+0000 (UTC) https://www.codechef.com/submit/VOTERS

#c++
star

Tue Jun 22 2021 02:54:54 GMT+0000 (UTC) https://github.com/imneonizer/How-to-find-if-an-image-is-bright-or-dark/

#python #c++
star

Fri Jun 18 2021 14:33:24 GMT+0000 (UTC) https://www.geeksforgeeks.org/reverse-a-string-in-c-cpp-different-methods/

#c++
star

Wed Jun 02 2021 16:09:47 GMT+0000 (UTC)

#c++
star

Wed Jun 02 2021 11:56:03 GMT+0000 (UTC)

#c++
star

Wed Jun 02 2021 10:39:55 GMT+0000 (UTC)

#c++
star

Wed Jun 02 2021 10:37:42 GMT+0000 (UTC)

#c++
star

Wed May 26 2021 22:05:48 GMT+0000 (UTC) https://stackoverflow.com/questions/5307169/what-is-the-meaning-of-a-c-wrapper-class

#c #c++ #wrapper
star

Wed May 26 2021 20:58:04 GMT+0000 (UTC) https://www.c-plusplus.net/forum/topic/270976/was-ist-ein-wrapper

#c #c++ #wrapper
star

Sat May 08 2021 17:17:06 GMT+0000 (UTC)

#c++
star

Mon May 03 2021 16:22:37 GMT+0000 (UTC)

#c++ #output #xcode #redirection
star

Mon May 03 2021 16:14:21 GMT+0000 (UTC)

#c++
star

Wed Apr 28 2021 00:56:03 GMT+0000 (UTC) https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work#:~:text=The%20compilation%20of%20a%20C%2B%2B%20program%20involves%20three%20steps%3A&text=Compilation%3A%20the%20compiler%20takes%20the,library%20or%20an%20executable%20file.

#c++
star

Tue Apr 20 2021 01:06:11 GMT+0000 (UTC) https://gitlab.eecs.umich.edu/eecs281/wiki/-/wikis/xcode-file-redirection

#c++ #output #xcode #redirection
star

Sat Apr 17 2021 00:49:25 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688332?%24web_only=true&~channel=email&~stage=published&utm_medium=email&utm_campaign=email&utm_source=sendgrid.com&_branch_match_id=890253272865013170#questions/14628310/

#c++
star

Thu Apr 15 2021 19:48:48 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688274#questions/10258738

#c++
star

Thu Apr 15 2021 17:02:27 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688272#questions/14617278

#c++
star

Thu Apr 15 2021 16:53:13 GMT+0000 (UTC)

#c++
star

Wed Apr 14 2021 17:38:00 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688272#questions/14612872/

#c++
star

Thu Apr 08 2021 21:39:39 GMT+0000 (UTC) https://stackoverflow.com/questions/10359702/c-filehandling-difference-between-iosapp-and-iosate#:~:text=ios%3A%3Aapp%20%22set%20the,file%20when%20you%20open%20it.&text=The%20ios%3A%3Aate%20option,to%20the%20end%20of%20file.

#c++
star

Fri Apr 02 2021 11:14:20 GMT+0000 (UTC)

#c++
star

Tue Mar 30 2021 13:35:34 GMT+0000 (UTC)

#c++
star

Mon Mar 29 2021 15:48:43 GMT+0000 (UTC) https://stackoverflow.com/questions/11938979/what-exception-classes-are-in-the-standard-c-library

#c++
star

Wed Mar 17 2021 04:14:46 GMT+0000 (UTC)

#c++
star

Wed Mar 17 2021 02:53:18 GMT+0000 (UTC)

#c++
star

Wed Mar 17 2021 01:58:37 GMT+0000 (UTC)

#c++
star

Wed Mar 17 2021 01:57:12 GMT+0000 (UTC)

#c++
star

Wed Mar 10 2021 03:42:55 GMT+0000 (UTC)

#c++
star

Tue Mar 09 2021 17:08:05 GMT+0000 (UTC)

#c++
star

Tue Jan 26 2021 22:43:21 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Thu Jan 21 2021 20:17:57 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Jan 20 2021 22:02:30 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Jan 12 2021 19:28:43 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Jan 12 2021 09:58:35 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Jan 09 2021 02:24:44 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Jan 08 2021 09:33:32 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Thu Jan 07 2021 06:42:04 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Jan 06 2021 21:53:09 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Jan 02 2021 17:54:04 GMT+0000 (UTC)

#c++
star

Tue Dec 29 2020 11:21:13 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Mon Dec 28 2020 03:44:59 GMT+0000 (UTC)

#c++
star

Sun Dec 20 2020 11:27:54 GMT+0000 (UTC) https://stackoverflow.com/questions/29995863/how-to-add-custom-code-snippets-in-vscode

#c++
star

Fri Dec 18 2020 02:16:44 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Dec 11 2020 21:08:00 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Dec 11 2020 20:09:09 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Dec 09 2020 03:00:16 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Thu Nov 26 2020 14:13:55 GMT+0000 (UTC)

#c++
star

Wed Nov 25 2020 01:54:07 GMT+0000 (UTC)

#c++
star

Sun Nov 15 2020 20:41:49 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sun Nov 15 2020 04:08:15 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sun Nov 15 2020 02:54:42 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Nov 13 2020 07:38:03 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Nov 13 2020 03:52:42 GMT+0000 (UTC)

#c++
star

Thu Nov 12 2020 14:28:30 GMT+0000 (UTC)

#c++
star

Wed Nov 11 2020 05:55:19 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Nov 10 2020 22:42:18 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Nov 10 2020 16:35:52 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Nov 10 2020 16:12:46 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Mon Nov 09 2020 07:53:26 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Mon Nov 09 2020 01:01:29 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sun Nov 08 2020 23:35:48 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Nov 07 2020 03:20:33 GMT+0000 (UTC) https://www.geeksforgeeks.org/lambda-expression-in-c/

#c++
star

Fri Nov 06 2020 17:32:33 GMT+0000 (UTC)

#c++
star

Fri Nov 06 2020 15:00:33 GMT+0000 (UTC)

#c++
star

Fri Nov 06 2020 14:49:48 GMT+0000 (UTC)

#c++
star

Fri Nov 06 2020 03:45:15 GMT+0000 (UTC)

#c++
star

Thu Nov 05 2020 20:47:39 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sun Nov 01 2020 20:05:47 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Oct 27 2020 08:04:05 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Oct 27 2020 02:55:57 GMT+0000 (UTC) https://zerojudge.tw/ShowProblem?problemid

#c++
star

Sun Oct 25 2020 03:45:41 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Oct 24 2020 17:58:24 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Oct 24 2020 11:35:47 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Oct 24 2020 03:24:57 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Oct 24 2020 02:47:16 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Oct 24 2020 01:37:34 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Oct 23 2020 07:14:14 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Oct 21 2020 08:25:33 GMT+0000 (UTC) https://www.javatpoint.com/fibonacci-series-in-cpp

#c++ #fibonacci
star

Wed Oct 21 2020 07:59:21 GMT+0000 (UTC)

#c++
star

Wed Oct 14 2020 22:19:09 GMT+0000 (UTC)

#c++
star

Wed Oct 14 2020 18:44:50 GMT+0000 (UTC)

#c++
star

Fri Sep 11 2020 14:28:11 GMT+0000 (UTC) https://www.technical-recipes.com/2011/simple-binary-tree-implementation/

#c++
star

Thu Jul 16 2020 13:01:21 GMT+0000 (UTC) https://github.com/an-tao/drogon

#c++ #web #rest
star

Wed Dec 25 2019 10:57:06 GMT+0000 (UTC) https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/

#c++ #algorithms #interviewquestions #arrays

Save snippets that work with our extensions   