Sandeep
Because string in C++ is not null terminated.
Theb how do I achieve the same function
Sandeep
Without changing the declaration to char pointer
Talula
Theb how do I achieve the same function
It keeps two things, length and pointer to the location where the information is stored.
Sandeep
Then how should I achieve. The same function
Sandeep
Like...in my code I replaced an index with null
Sandeep
Strlen that stops after null
Talula
Strlen that stops after null
Use char * or C styled string... but if you want to do the same in C++ you can make the string shorter...
Talula
Like if S1 = "Hello, world" And you want to terminate it at Hello, then make S1 = "Hello".
Anonymous
Is string notation in C++ diffrent from C? In C strlen calculates lenght of string with delimiter null charecter included! And if we use charecter pointer to denote string u cannot assign null value
Talula
What if I want to shorten it till null
Then you find where you gonna fit null and do like this S1 = S1.substr(0, LocationOfNull);
Anonymous
Hello
Anonymous
Is anyone here who knows c very well? I need help
klimi
Is anyone here who knows c very well? I need help
What so you think? There is 14k users in this c/c++ group...
Anonymous
For what?
A question
Anonymous
For what?
I want a program that writes every 3 digits number with{1,2,3,5,7} as output without any repeated number in their digits
Anonymous
Can someone help please
klimi
you can do that easily with some recursion
Anonymous
you can do that easily with some recursion
Yes but I don't know much about recursive functions Can you help me?
klimi
just break it down to smaller problems, how do you generate one digit number with those options?
Anonymous
I undrestand the question I don't knwo how to write it in c language.
Anonymous
I undrestand the question I don't knwo how to write it in c language.
If I show you C++ code that does what you want with repetitions will you be able to change it so that it does it without repetitions?
Anonymous
To change
Anonymous
#include <iostream> #include <string> #include <algorithm> #include <fstream> #include <set> #include <iterator> std::set<std::string> perms; void permutations(std::string inp, int required_length, std::string gen= ""){ if (required_length == 0) { perms.insert(gen); return; } for (int j = 0; j < inp.size(); j++) { std::string tmp = gen + inp[j]; permutations(inp, required_length - 1, tmp); } return; } int main() { std::string inp = "abc"; std::sort(inp.begin(), inp.end()); //for permutations in alphabetical order permutations(inp, 7); //Generate permutations of length 7 std::fstream f("output.txt", std::fstream::out); std::ostream_iterator<std::string> iter(f, "\n"); std::copy(perms.begin(), perms.end(), iter); } This should work. It is slow for permutations greater than 11 in size but I checked the std::next_permutation algorithm which also had almost the same performance (slightly faster) though it doesnt do permutations with repetitions unlike this one. The algorithm in the standard library just does a permutation of the input string and doesnt consider repetitions of characters multiple times (more than the number of times it is present in the input) as a possiblility. The above code treats the input string as a alphabet set and generates all possible strings of the given length from them which is what you wanted I guess. So this should be ok.
@Antusme here you go. Change inp to "12357" and change the line permutations(inp,7) to permutations(inp,3). This will show all 3 digit numbers with repetitions. Now change it so that repetition of digits are not allowed.
Anonymous
#include <iostream> #include <string> #include <algorithm> #include <fstream> #include <set> #include <iterator> std::set<std::string> perms; void permutations(std::string inp, int required_length, std::string gen= ""){ if (required_length == 0) { perms.insert(gen); return; } for (int j = 0; j < inp.size(); j++) { std::string tmp = gen + inp[j]; permutations(inp, required_length - 1, tmp); } return; } int main() { std::string inp = "abc"; std::sort(inp.begin(), inp.end()); //for permutations in alphabetical order permutations(inp, 7); //Generate permutations of length 7 std::fstream f("output.txt", std::fstream::out); std::ostream_iterator<std::string> iter(f, "\n"); std::copy(perms.begin(), perms.end(), iter); } This should work. It is slow for permutations greater than 11 in size but I checked the std::next_permutation algorithm which also had almost the same performance (slightly faster) though it doesnt do permutations with repetitions unlike this one. The algorithm in the standard library just does a permutation of the input string and doesnt consider repetitions of characters multiple times (more than the number of times it is present in the input) as a possiblility. The above code treats the input string as a alphabet set and generates all possible strings of the given length from them which is what you wanted I guess. So this should be ok.
Did you use all these libraries in the program?
Anonymous
I am unfamiliar with most of them
Anonymous
Can I ask another question?
Anonymous
Did you use all these libraries in the program?
Just look at the permutations function alone.
Anonymous
I want to send a screenshot
Anonymous
Can I pm?
No. I am not going to help you anymore with this. You just have to understand the logic of permutations function and there is not much C++ there which is different from C code. You have to do some work on your own.
Anonymous
Hey I had made a calci at c which works when it is opened in vs code or in code blocks but when I open it from the folder it opens but do not works
Ravi
from folder?
Anonymous
Anonymous
Yes I can open it
So what happens? Does the terminal window close immediately?
Ravi
Yes I can open it
Simply put getch at the end of the code compile it and open it from folder
Anonymous
But the thing is I can't get the answer For eg 2 + 2 Then the program ends
Ravi
Of take any fake input at the end of the program.
Anonymous
yes exactly
Do what Ravi suggested 2 messages above. Just add a getch() at the end of your main function.
Anonymous
Btw I have some more problems
Anonymous
https://dpaste.org/ULGK This is the code for a simple graphic less snake game strangely which only runs in code blocks not in vs code I just want to decrease the speed and increase the area I tried to do the same but the result that came wasn't in my favour
Anonymous
Do what Ravi suggested 2 messages above. Just add a getch() at the end of your main function.
Should I know c completely to learn other programming languages?
Anonymous
https://hastebin.com/pigozacoko.rust can someone help me with line 40 and 48? my mind is melting trying to figure it out from books. how does rotation impact the balance factors? btw it is C and not rust
Anonymous
My memory is a bit hazy but I guess AVL trees keep the height difference to atmost 1
Anonymous
So how r u doing it?
storing the balance factor instead. i figured out how the insertion itself changes it and how the change propagates, but not rebalancing.
Anonymous
storing the balance factor instead. i figured out how the insertion itself changes it and how the change propagates, but not rebalancing.
So basically looking at your insertion logic suggests that u r storing the difference between the left and right sub tree height as balance factor in the parent node
Anonymous
yes
Well you would be doing rotations when balance factor is +2 or -2. The actual rotations done also depend on the balance factor of the children. For a rotation where parent node is at +2 (left node is deeper) and left node's left node is deeper (meaning the insertion was done there), you would be making the left child the parent and the parent the right child of this node. You would also make the right child of this previously left child node, the left child of the previous parent node. Consider what this does to the balance factor. The balance factor of root node would be now 0 as would the balance factor for all the other nodes involved in the rotation. So instead of just a simple left and right rotation, you should consider 4 cases where the balance can be impacted. Insertion in left subtree of left node. Insertion in right subtree of left node, insertion in left subtree of right node and insertion in right subtree of right node. As long as your tree has a balance factor <=1, these rotations would preserve them. Basically what am suggesting is that update the balance factor at the end of these multiple rotations rather than at the end of individual left or a right rotation. Have something called left_left_rotate (in this case you would doing just one right rotation but all the nodes involved will have a balance factor of 0 after rotation), left_right_rotate(you would be doing a single right rotate followed by a single left rotate) and the balance factor of all nodes involved will be 0 after rotation, right_right_rotate (a single left rotate) and balance factor would be 0 for all nodes involved and a right_left_rotate(a left rotate followed by right rotate) and balance factor of all nodes involved would be 0 after both rotations. This way you dont have to scratch your head thinking about what the balance factor will be after each individual rotate. Sometimes you might need two rotations and sometimes just a single rotation.
Anonymous
Well you would be doing rotations when balance factor is +2 or -2. The actual rotations done also depend on the balance factor of the children. For a rotation where parent node is at +2 (left node is deeper) and left node's left node is deeper (meaning the insertion was done there), you would be making the left child the parent and the parent the right child of this node. You would also make the right child of this previously left child node, the left child of the previous parent node. Consider what this does to the balance factor. The balance factor of root node would be now 0 as would the balance factor for all the other nodes involved in the rotation. So instead of just a simple left and right rotation, you should consider 4 cases where the balance can be impacted. Insertion in left subtree of left node. Insertion in right subtree of left node, insertion in left subtree of right node and insertion in right subtree of right node. As long as your tree has a balance factor <=1, these rotations would preserve them. Basically what am suggesting is that update the balance factor at the end of these multiple rotations rather than at the end of individual left or a right rotation. Have something called left_left_rotate (in this case you would doing just one right rotation but all the nodes involved will have a balance factor of 0 after rotation), left_right_rotate(you would be doing a single right rotate followed by a single left rotate) and the balance factor of all nodes involved will be 0 after rotation, right_right_rotate (a single left rotate) and balance factor would be 0 for all nodes involved and a right_left_rotate(a left rotate followed by right rotate) and balance factor of all nodes involved would be 0 after both rotations. This way you dont have to scratch your head thinking about what the balance factor will be after each individual rotate. Sometimes you might need two rotations and sometimes just a single rotation.
that makes sense. i was trying to call left_rotation followed by right_rotation instead of having a left_right_rotate function so i thought it would be appropriate for the rotations changing the balance factor themselves. i will let the rotation functions just perform the rotation and update the balance factors at the call site instead.
Anonymous
Does queue STL increase its size itself? Like, when I do push_back in vector it gets automatically resized. Is it the same for queue? I heard that they have size_t though.
Anonymous
Does queue STL increase its size itself? Like, when I do push_back in vector it gets automatically resized. Is it the same for queue? I heard that they have size_t though.
The queue like stack is an adapter class. By default it uses std::deque as its underlying container. So any push operation will increase the size of the deque container and in effect the size of the queue adapter just like it happens with a plain vector.
Talula
I want a program that writes every 3 digits number with{1,2,3,5,7} as output without any repeated number in their digits
Start writing and when you feel you're stuck we can help you out, but we should not be doing your home work.
Kaddy
I want a program that writes every 3 digits number with{1,2,3,5,7} as output without any repeated number in their digits
Here's food for thought: Suppose S_A is the set of all permutations of digits in set A={1, 2, 3, 5, 7} Then S = S_1 + S_2 + S_3 + S_5 + S_7 Where S_x is the set of permutations starting with digit 'x'. So essentially, you can write a recursive function which 'fixes' first digit as something, say 3 and then calls itself on the subset A-{3} and so on… I hope you get the idea
Kaddy
try to convert this idea into code
Anonymous
Is udemy is helpfull for learn hacking
Anonymous
Is udemy is helpfull for learn hacking
When people say hacking they usually mean penetration testing. I have no background on this but my company recruits penetration testers who have been certified by Offensive Security. They have the best courses for penetration testing and you cant clear them without considerable effort from your side. Start with their OSCP certification and WiFu certification and move on to CTP, OSWE and OSEE. Their OSEE and CTP courses are very tough to clear and the lead for penetration testing team in my company (he has a brilliant mind) took 3 attempts to clear it. That would give you an idea.
Pavel
NASM, elf64 section .text global _start _start: mov eax, 1000000000 .l1: dec eax jnz .l1 mov rax, 0 ret Why do I get SIGSEGV?
Pavel
Got it, thanks
Anonymous
i would also start from the very basics, iso osi and tcp/ip
That is something they expect people to know before they even register for their courses. Basically you should be comfortable with Python, bash and Linux OS (daily use) in general. For CTP and OSEE, they also need you to know additional things like C/C++, assembly amongst others.