Anonymous
Shahar
Thank you
Anonymous
(z=x³+y³-xy/z)..can someone assist to write c++ expresion for this
Puspam
mito
z=x*x*x+y*y*y-x*y/z
I always feel uncomfortable writing expressions like this without parentheses..
Gabriel
How I can mix C and C++ without suffering?
Gabriel
I know about the name mangle and other stuff things about the difference between both languages!
Diego
Well I mean for starters you shouldn't
Diego
But if you're really inclined to, then just make a C++ project and there's a keyword to denote C code in a C++ project
Diego
https://isocpp.org/wiki/faq/mixing-c-and-cpp
Gabriel
Diego
Afaik C++ only has C support as legacy support — so I don't think any standard C compiler would allow you to do that
Diego
Don't take my word for it though
Gabriel
Hmm ok, I will avoid this idea, and use another language in the place like Fortran!
...
Gabriel
Gabriel
Anonymous
abc
Why it is bad programming practice to use %[\n]s in scanf??
Anonymous
Why it is bad programming practice to use %[\n]s in scanf??
This format specifier doesnt make any sense. You are asking scanf to read everything till a newline character is encountered and then you ask it to read s. But the problem is that \n is still in the buffer as [\n] does not consume the new line.
abc
abc
Anonymous
Anonymous
abc
Anonymous
abc
Thanks man, I'll look for some examples on the internet
Manav
Given an array arr[] of size N. The task is to find the first repeating element in an
array of integers, i.e., an element that occurs more than once and whose index of
first occurrence is smallest.
Manav
Manav
Input:
7
1 5 3 4 3 5 6
Output:
2
Anonymous
Input:
7
1 5 3 4 3 5 6
Output:
2
The repeating elements are 3, 5.
The first occurrence index of 3 is 3(1-indexed).
The first occurrence index of 5 is 2.
So output 2.
Manav
Means firstly we find the repeating element the the element has smallest index is the output
Anonymous
Anonymous
Anonymous
Hmms.. but he posted the qn as "The task is to find the first repeating element in an array of integers"
Anonymous
But his example output is 2 , not 5.
Sandeep
What's the difference between unordered map and just map
Anonymous
What's the difference between unordered map and just map
Unordered map uses hashing to decide the bucket in which elements must be stored. Map on the other hand uses a tree like data structure. Most of the C++ standard library implementations use a RB Tree. Maps store elements in a sorted order.
Sandeep
DEV 7
why we use protected mode in c++ ?? in simple terms
DEV 7
thanks
Golden Age Of
thanks
or you need to make your parent not creatable(you create constructors in protected or private sections), but its not a good practice sometimes
DEV 7
Puspam
PS
Hi anyone here??? I have a doubt
PS
How should i optimize this???
vector<int> Solution::solve(vector<int> &A) {
int n = A.size();
vector<int> res;
for(int i = 0; i<n; i++){
int cnt = 0;
for(int j=0; j<n; j++){
if(A[i]%A[j]==0 || A[j]%A[i]==0){
cnt++;
}
}
res.push_back(cnt-1);
}
return res;
}
Golden Age Of
PS
Media isn’t allowed the question asked me return an integer array containing the number of friend of each person
PS
A= [2,3,4,5,6]- input array
PS
Output- [2,1,1,0,2]
Explanation- A person i will be friends with j only if either(A[i]%A[j]==0 || A[j]%A[i]==0)
PS
For output i used vector res where i pushed count for each element’s no of friends
Anonymous
A= [2,3,4,5,6]- input array
Is there a constraint on the range of values in your input array like say it will always be between 1 and 100 or so on?
PS
For N ,number of elements in array 1 to 2 * 10^5
For A[i] - 1 to 10^5
PS
My program is 50 % i just need to optimize it to get 100%
PS
* correct
Apk
PS
Apk
I just want help
Better discuss exam questions after it gets over. Or this is not the right place.
Anonymous
For N ,number of elements in array 1 to 2 * 10^5
For A[i] - 1 to 10^5
Then your solution seems to be a good one. Change the inner loop to go from i+1 to n so that you skip pairs that you have already checked. The complexity will be n^2 anyway and it may timeout.
If the range were narrower, you could have used a multi map and check if multiples of a number in A are present in the multi map and how many such occurrences. It would reduce the complexity to klogN where k is (max input in array)/(smallest input in array) but for the input range you have been given this would be inefficient.
Sag
This should work but not working
Sag
Sag
Both are same thing
Sag
Okay, if I'm not demanding too much what does you use to debug??