Anonymous
Ah, you mean in Python, the VM (written in C) is actually an executable receiving as an input Python code, and converting it to is suitable byte-code, which is in its turn decoded to machine-code using an LLVM?
No. The interpreter is just that. It executes each Python statement sequentially. There is no compiling that happens but off late Python interpreters have grown to include Just In Time compilers which compile code that is called often so that they execute faster. No more Python questions.
Anonymous
so the VM is an executable written in C, which receives Python code and outputs respective byte-code?
This is not a Python group. Please ask questions related to Python in a group meant for that.
Shahar
Thank you
Anonymous
(z=x³+y³-xy/z)..can someone assist to write c++ expresion for this
Anonymous
z=x*x*x+y*y*y-x*y/z
Ooh wow ..thanks ...i couldnt figue out
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
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
Hmm I understand, but what I really want is to create a C project and call C++ subroutines. I think that this does work...
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!
...
Hmm I understand, but what I really want is to create a C project and call C++ subroutines. I think that this does work...
just write c style wrappers arround the c++ code https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-cpp
Diego
Hmm ok, I will avoid this idea, and use another language in the place like Fortran!
Yeah it's probably for the best! If you're having to do lots of tricks, it's better to switch to more fitting technologies while you still can!
Puspam
I always feel uncomfortable writing expressions like this without parentheses..
You should avoid parenthesis wherever you can. Unnecessary parenthesis can slow down the execution a little bit.
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.
Anonymous
But still we can use fflush(stdin) to delete anything which present in buffer
fflush(stdin) is not standard supported and leads to Undefined Behavior on most implementations. fflush is meant to be used with output streams and not input streams. fflush will work on input streams only if the underlying stream is seekable.
Anonymous
But still we can use fflush(stdin) to delete anything which present in buffer
Moreover in scanf "%[\n]s" where exactly will the fflush call be (assuming it works)?
abc
Moreover in scanf "%[\n]s" where exactly will the fflush call be (assuming it works)?
I thought after using scanf, I can use fflush (stdin) to delete whatever present in input buffer
Anonymous
I thought after using scanf, I can use fflush (stdin) to delete whatever present in input buffer
So what is the point of s format specifier then? That is why I said it is illogical.
abc
So what is the point of s format specifier then? That is why I said it is illogical.
Thanks I got it But why using fflush (stdin) leads to undefined behaviour??
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
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
Means firstly we find the repeating element the the element has smallest index is the output
No. The output is not the element itself but the index (indexes start from 1) The question is "Find the index (1-Indexed) of the first repeating element in the given array."
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.
Apk
But his example output is 2 , not 5.
It must be considering 0-based indexing🤔
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.
DEV 7
why we use protected mode in c++ ?? in simple terms
Golden Age Of
why we use protected mode in c++ ?? in simple terms
if you want for example , some variables of parent would be accessible in child class
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
Puspam
???? This is completely untrue.
You are right. Compilers generally optimize the expressions. But it is true for interpreted languages.
Anonymous
You are right. Compilers generally optimize the expressions. But it is true for interpreted languages.
Even for interpreted languages, most of the interpreters do an initial phase of compilation where comments are stripped and extraneous parentheses removed. So comments and parentheses may at best slow down this compilation process but will have absolutely no impact on running time (execution time) of the code.
PS
Hi anyone here??? I have a doubt
Golden Age Of
Hi anyone here??? I have a doubt
1k online, just describe your problem
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
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
// Node *swapNodes(Node *head, int i, int j) // { // // Base condition // int length=len(head); // if(head==NULL || head->next==NULL || i==j ){ // return head; // } // // Getting all the vairiable fill // Node *prev1=head; // Node *prev2=head; // Node *n1=head; // Node *n2=head; // for(int i1=0; i1<i-1; i1++){ // prev1=prev1->next; // } // n1=prev1->next; // for(int j1=0; j1<j-1; j1++){ // prev2=prev2->next; // } // n2=prev2->next; // // Checking condition and getting out output according to them // if((i==0 || j==0) && (i-j)==1){ // Node *temp=head; // head=head->next; // temp->next=head->next; // head->next=temp; // return head; // } // else if((i==0 || j==0) && (j-i)==1){ // Node *temp3=head; // head=head->next; // temp3->next=head->next; // head->next=temp3; // return head; // } // else if((i==0 || j==0) && (j-i)>1){ // Node*temp1=head; // prev2->next=n2->next; // head=n2; // head->next=temp1->next; // temp1->next=prev2->next; // prev2->next=temp1; // return head; // } // else if((i==0 || j==0) && (i-j)>1){ // Node*temp2=head; // prev1->next=n1->next; // head=n1; // head->next=temp2->next; // temp2->next=prev1->next; // prev1->next=temp2; // return head; // } // else if((i-j)==-1){ // prev1->next=n1->next; // n1->next=n2->next; // n2->next=n1; // return head; // } // else if((i-j)>=1){ // prev2->next=n1; // prev1->next=n2; // n2->next=n1->next; // n1->next=prev1; // return head; // } // else if((j-i)>1){ // prev1->next=n2; // prev2->next=n1; // n1->next=n2->next; // n2->next=prev2; // return head; // } // }
Sag
This should work but not working
Anonymous
This should work but not working
This should be debugged but not being debugged.
Sag
Both are same thing
Anonymous
What does this mean??
Means "Use a debugger"
klimi
This should work but not working
um just a silly question, are those all comments?
Sag
Okay, if I'm not demanding too much what does you use to debug??