Anonymous
Can be only integer numbers
You should understand that part of being a programmer is to speak " english ", I know it might not be your native language, but don't expect to get help and you can't even write
a decent explaination and example of input and output for the problem..
Margo
Shubh Joshi
klimi
SMS
Why is this?
x++ may generate a temporary variable, to represent the previous value of this variable.
but in this case, it is the same. the compiler will take care of it
klimi
\Device\NUL
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t,n,x,y,i,j,k,a,b;
cin>>t;
char ch;
string s,s1,s2;
for(i=0;i<t;i++)
{
k=0;
y=0;
cin>>s;
n=s.length();
for(j=0;j<n/2;j++)
{
s1[j]=s[j];
}
if(n%2==0)
{
for(j=n/2;j<n;j++)
{
s2[j]=s[j];
}
}
else if(n%2!=0)
{
for(j=n/2+1;j<n;j++)
{
s2[k]=s[j];
k++;
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s1[j]>s1[j+1])
{
ch=s1[j];
s1[j]=s1[j+1];
s1[j+1]=ch;
}
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s2[j]>s2[j+1])
{
ch=s1[j];
s2[j]=s2[j+1];
s2[j+1]=ch;
}
}
}
if((s1.compare(s2))==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
https://www.quora.com/Is-it-good-practice-to-use-include-bits-stdc++-h-in-programming-contests-instead-of-listing-a-lot-of-includes
Shubh Joshi
Anonymous
Hello any expert in SAS programming?
ꍏꈤꀸ
Hi, how can i asynchronously call some function N times and get results?
Here's what i tried with std::packaged_task, but i can' call it more than once:
std::packaged_task packagedTask{ [] {} };
//packagedTask.get_future(); // way to get result afterwards
packagedTask();
packagedTask(); // future_error - promise already satisfied
*Note1: I want to control by myself when and where function is executed
*Note2: I'm limited with C++ 11
Ludovic 'Archivist'
Ludovic 'Archivist'
Евгений
First, learn how to Google, bro:)))
klimi
place comments? if you have written the code, you should be able to say what it does
Anonymous
Anonymous
Anonymous
Anshul
Евгений
Евгений
Евгений
D
double getNumbers()
{
double answer = 0.0;
bool numbersGotten = false;
int const SIZE = 3;
double numbers[SIZE];
int i = 0;
// Input - Numbers
cout << "\nEnter three numbers separated by a space: ";
for (i = 0; i < SIZE; i++)
{
cin >> numbers[i];
}
answer = numbers[i];
return answer;
}
double add()
{
int i = 0;
int const SIZE = 3;
double numbers[SIZE];
double answer = 0;
// Calculation
answer = numbers[0];
for (i = 1; i < SIZE; i++)
{
answer += numbers[i];
}
// Output
cout << "\nAnswer: " << answer << ", i.e., ";
cout << numbers[0];
for (i = 1; i < SIZE; i++)
{
cout << " + " << numbers[i];
}
cout << "\n";
answer = numbers[i];
return answer;
}
can someone please help me , i want to know how can i get the values i inputed in the first function and place them in the second function in order to perform the addition thanks
Anonymous
.?
Could be because of the allocation of array cs on stack. Sometimes stack memory allocated by default is on the lower side and maybe that is why your code is getting a segmentation fault.
Anshul
Anshul
Anshul
Anonymous
Anonymous
Anshul
But I am using more stack memory then why doesn't it affect anything
Anshul
If it won't affect then why isn't it kept a larger value already😐
Anshul
klimi
klimi
.......................
Please help with this problem
Consider the following program in C++11/14 to compute the product of a number of elements.
Fill in the blanks as per the instructions given below:
• at LINE-1 with appropriate periodic template for function product,
• at LINE-2 with appropriate body of the product function,
such that it will satisfy the given test cases.
Select the Language for this assignment.
C++
1
#include <iostream>
2
3
template <typename T>
4
double product(T num){ return num; }
5
6
________ //LINE-1
7
8
double product(T num, Tail... nums){
9
10
________; //LINE-2
11
}
0
int main(){
1
int a, b;
2
double c, d;
3
std::cin >> a >> b >> c >> d;
4
std::cout << product(a, b) << std::endl;
5
std::cout << product(c, d) << std::endl;
6
std::cout << product(a, b, c, d) << std::endl;
7
return 0;
8
}
Tate
Hello need help with a question if anyone can help
Tate
Write a C program that creates a function bitFlip() that takes an int parameter and returns an int that has all of the int that was passed in bits flipped.
It changes all 0s to 1s and all 1s to 0s. In the main function, read in an int num using scanf, call bitFlip(), and the function returns num with its bits flipped.
Евгений
It's easy, bro. Just Google bitwise operations
Anonymous
Emran Hasan
Which app is best for c coding? For Android 🙏
Евгений
Learncpp.com
Евгений
Very good arranged, i guess it's chapter 6, or O, not zero, bro.
Anonymous
Any programmer available... I need one for my startup
Emran Hasan
🙋🏻♂️
Guys
🙋🏻♂️
Can anyone tell me what a state machine is?
Anonymous
You are given a 3x3 matrix of positive integers. You have to
determine whether some row is a positive integer multiple of
another.
If row i is an integer multiple of row j, then you have
to output
p#q where p is the minimum of (i,j) and q is the maximum of (i,j).
If there are multiple possibilities for i and j, you have to print for the
smallest i and the smallest j.
Otherwise, you have to output
0#0
Anonymous
for int i=1;i<=3;i++{
for int j=1;j=<3;j++{
if (i*j)%j=0 printf ("p#q")
else printf("0#0");
}
}
Peace
how to increment int value of vector of pairs ?
vector<pair<string,int>> ques;
like below :
for(auto row: questions){
row.second++;
}
Anshul
https://pastebin.com/hjC5LHRb
in this code when i run it on leetcode i am getting runtime error but on my machine it runs fine
Anonymous
Please identify mistake i might have done here
#include <iostream> 
// 
using namespace std; 
// 
class Object //Abstract class in C++ 
{ 
public : 
void show () = 0; //pure virtual function  
}; 
// 
class ArithmeticAdd : public Object  
{ 
int res; 
public: 
void add (int a, int b) { 
res = a + b ; 
} 
void add (int a, int b, int c) // Function overloading - Static Binding  
{ 
res = a + b + c; 
} 
void show () { 
cout << "Result = " << res; 
} 
}; 
// 
class Complex : public Object  
{ 
int real; 
int img; 
public : 
Complex Add (Complex C1, Complex2) { 
real = C1.real + C2.real; 
img = C1.img + C2.img; 
return this; 
} 
void show () { 
cout << real << " + " << img << "i" <<endl; 
} 
friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading  
}; 
// 
istream & operator >> (istream & in, Complex & c)  
{ 
in >> c.real >> c.img; 
return in; 
} 
// 
int main ()  
{ 
Object o [2]; 
ArithmeticAdd a; 
a.add (2,6); 
o [0] = &a; 
o [0].show (); // Dynamic dispatch - run time polymorphisms  
a.add (9,11,23); 
o [0].show (); 
Complex C1, C2, C3, C4; 
cin >> C1; 
cin >> C2; 
C4 = C3.Add (C1, C2); // Message passing  
o [1] = & C4; 
o [1].show (); 
return 0; 
} 
Peace
Anshul
Please identify mistake i might have done here
#include <iostream> 
// 
using namespace std; 
// 
class Object //Abstract class in C++ 
{ 
public : 
void show () = 0; //pure virtual function  
}; 
// 
class ArithmeticAdd : public Object  
{ 
int res; 
public: 
void add (int a, int b) { 
res = a + b ; 
} 
void add (int a, int b, int c) // Function overloading - Static Binding  
{ 
res = a + b + c; 
} 
void show () { 
cout << "Result = " << res; 
} 
}; 
// 
class Complex : public Object  
{ 
int real; 
int img; 
public : 
Complex Add (Complex C1, Complex2) { 
real = C1.real + C2.real; 
img = C1.img + C2.img; 
return this; 
} 
void show () { 
cout << real << " + " << img << "i" <<endl; 
} 
friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading  
}; 
// 
istream & operator >> (istream & in, Complex & c)  
{ 
in >> c.real >> c.img; 
return in; 
} 
// 
int main ()  
{ 
Object o [2]; 
ArithmeticAdd a; 
a.add (2,6); 
o [0] = &a; 
o [0].show (); // Dynamic dispatch - run time polymorphisms  
a.add (9,11,23); 
o [0].show (); 
Complex C1, C2, C3, C4; 
cin >> C1; 
cin >> C2; 
C4 = C3.Add (C1, C2); // Message passing  
o [1] = & C4; 
o [1].show (); 
return 0; 
} 
what is the error that you're getting
Anshul
#include <iostream>
//
using namespace std;
//
class Object //Abstract class in C++
{
public :
void virtual show() = 0; //pure virtual function
};
//
class ArithmeticAdd : public Object
{
int res;
public:
void add (int a, int b) {
res = a + b ;
}
void add (int a, int b, int c) // Function overloading - Static Binding
{
res = a + b + c;
}
void show () {
cout << "Result = " << res;
}
};
//
class Complex : public Object
{
int real;
int img;
public :
Complex Add (Complex C1, Complex C2) {
real = C1.real + C2.real;
img = C1.img + C2.img;
return *this;
}
void show () {
cout << real << " + " << img << "i" <<endl;
}
friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading
};
//
istream & operator >> (istream & in, Complex & c)
{
in >> c.real >> c.img;
return in;
}
//
int main ()
{
//Object o [2];
ArithmeticAdd a;
a.add (2,6);
//o [0] = &a;
//o [0].show (); // Dynamic dispatch - run time polymorphisms
a.add (9,11,23);
//o [0].show ();
Complex C1, C2, C3, C4;
cin >> C1;
cin >> C2;
C4 = C3.Add (C1, C2); // Message passing
//o [1] = & C4;
//o [1].show ();
return 0;
}
Munir
hello Anyone who have W3schools full access account for sharing ?
Anshul
1. in show, you need to mention it is a virtual function by using virtual keyword
2. you can't return "this" as Complex
3. Object is an abstract class, so you can't create it's object
Anshul
klimi
Anonymous
Anshul
#include <iostream>
//
using namespace std;
//
class Object //Abstract class in C++
{
public :
void virtual show() = 0; //pure virtual function
};
//
class ArithmeticAdd : public Object
{
int res;
public:
void add (int a, int b) {
res = a + b ;
}
void add (int a, int b, int c) // Function overloading - Static Binding
{
res = a + b + c;
}
void show () {
cout << "Result = " << res;
}
};
//
class Complex : public Object
{
int real;
int img;
public :
Complex Add (Complex C1, Complex C2) {
real = C1.real + C2.real;
img = C1.img + C2.img;
return *this;
}
void show () {
cout << real << " + " << img << "i" <<endl;
}
friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading
};
//
istream & operator >> (istream & in, Complex & c)
{
in >> c.real >> c.img;
return in;
}
//
int main ()
{
//Object o [2];
ArithmeticAdd a;
a.add (2,6);
//o [0] = &a;
//o [0].show (); // Dynamic dispatch - run time polymorphisms
a.add (9,11,23);
//o [0].show ();
Complex C1, C2, C3, C4;
cin >> C1;
cin >> C2;
C4 = C3.Add (C1, C2); // Message passing
//o [1] = & C4;
//o [1].show ();
return 0;
}
This works
Anshul
Shubh Joshi
Hello coders
I want to print 10^9 in c++
I have tried to find it on Google and I get something.
But still I am facing some problem
So please help me.... suggest easiest way to print that type of very big number
Thanks in advance 👍
Kavy
Shubh Joshi
Sorry...but I want to print 10 digit number....which user will input
Not only 10 to the power
Shubh Joshi
Kavy thanks
From double...I hv done it🙌👍👍
Kavy
https://youtu.be/xCR6TrfFSao
|▪️𝕋𝕆ℕ𝕐 𝕊𝕋𝔸ℝ𝕂 ▪️|
You are given a sequence of positive numbers terminated with a
-1. Some initial portion of the sequence is monotone
non-decreasing. You can assume that the non-decreasing part has at
least 2 elements and the part after that also has at least one
element.
The first element starts at index 0.
You have to output the index i which represents the end of the
monotone non-decreasing part.
You can refer to the public inputs and outputs for clarification.
|▪️𝕋𝕆ℕ𝕐 𝕊𝕋𝔸ℝ𝕂 ▪️|
can i get solution to this
Lombord
Hi guys
I
Hello. Can anyone help me with this line of code that casts void* as char**, I can't find anything about it:
char **dynamic_str_1 = (char **)malloc(sizeof(char) * 8);
what the heck is going on here?