Maxter
In this ques
Maxter
I am doing this one using the longest common subsequence
Maxter
string reverse1(string& s){ int i=0; int j= s.size()-1; while(i<j){ char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return s; } int longestCommonSubsequence(string text1, string text2) { int m[1001][1001]={0}; for(auto i=0;i<text1.length();i++){ for(auto j=0;j<text2.length();j++){ m[i+1][j+1]=text1[i]==text2[j]?1+m[i][j]:max(m[i+1][j],m[i][j+1]); } } return m[text1.length()][text2.length()]; } int longestPalinSubseq(string A) { string m= reverse1(A); return longestCommonSubsequence(A,reverse()); }
Maxter
this one is returning the length of the string everytime
Ly Sophavin
Thank you 💖
Jaime
👍
Гулящий
Hi. I'm overloading the operator new for my class(for logging purposes). I'd like to write something to logs and then just call the basic normal new. Is it possible or I have to use malloc?
Гулящий
It's possible
Could you please give me a hint, how?
pavel
You just need to make global object to access your log. And do like this void * operator new(size_t size) { cout<< "Overloading new operator with size: " << size << endl; void * p = ::operator new(size); //void * p = malloc(size); will also work fine return p; }
Гулящий
Thanks a lot.
²
hey, this macros didnt work why, I can't understand #define FMTF(LEN) "%"LEN"s[^\n]" ?
Anonymous
string reverse1(string& s){ int i=0; int j= s.size()-1; while(i<j){ char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return s; } int longestCommonSubsequence(string text1, string text2) { int m[1001][1001]={0}; for(auto i=0;i<text1.length();i++){ for(auto j=0;j<text2.length();j++){ m[i+1][j+1]=text1[i]==text2[j]?1+m[i][j]:max(m[i+1][j],m[i][j+1]); } } return m[text1.length()][text2.length()]; } int longestPalinSubseq(string A) { string m= reverse1(A); return longestCommonSubsequence(A,reverse()); }
Check your reverse logic. You are passing a string by reference. So any changes that you do will be on the string itself and you are returning the changed string by value. So suppose the string s is "hello" and then you do string m = reverse1(s) then both s and m will be "olleh". Since the strings are the same, the longest subsequence will return the length of the entire string.
Abdelghani
hey there, I looking for a course about c for an intermediate level. thanks in advance!
Mustafo
My code has cout and cin functions, but when i run it, my vs code terminal doesn't show any of them
Mustafo
What am i doing wrong
Mustafo
i can send a screenshot on personal chat
klimi
Just send your code
Mustafo
int main() { cout << "Hello"; cout << "Введите два числа:" << endl; double a, b; cin >> a >> b; double result; #ifdef SQUARE result = SQUARE(a,b); #else result = P(a,b); #endif cout << "Результат: " << result << endl; return 0; }
Mustafo
And this code compiles?
yeap, the problem is that it runs executable
klimi
yeap, the problem is that it runs executable
Well then sadly I am unable to help you as I am not user of vscode
Mustafo
I use mac
Raghu
Any trainers in the group who can train a 11 year old on C programming and make him do some real projects
Raghu
Apologies I haven’t read the rules
Anonymous
Hi I’m learning the fundamentals but what do I do next after I know the fundamentals of programming in c
Anonymous
Okay how can I get into mostly networking side in c++ and can I pm you for mathematical advice
Vez_Man
Please any material or ebook on this
mito
Please any material or ebook on this
mathisfun.com Basic school math. Introduction to the Design and Analysis of Algorithms: International Edition https://www.amazon.in/dp/B00XN47AS0/ref=cm_sw_r_apan_H2QJX5VJ8YC1KJ2DH3BH Then, this I guess.
mito
You're welcome
Alireza
when I put a file in resource file ,does compiler use this file as a binary file??
AMA
Hello all! I'm faced with the task of creating a header and .c file that simulates a clock. The library is to create the following Clock* createNewClock(int h, int m, int s); void resetToMidnight(Clock *call); _Bool isMorning(Clock *clk); void advanceSeconds(Clock *clk, int secs); void printClock(Click *clk); However my problem is I don't know how to implement the "Clock* createNewClock(int h, int m, int s);" aspect. Is it a function that returns the value or what? How do I create it? I know I can create struct of clock but that isn't the syntax of creating struct.
AMA
what is the tree for?
So I could create the Clock* type
Hizmu(Vlad)
So I could create the Clock* type
No, what do you want to use it for? What function does it perform?
Anonymous
Can I get the link to Offtopic group chat?
Anonymous
Is Clion good for beginners?
Pavel
Is Clion good for beginners?
Yes, pretty much, maybe even better for beginners, because it is slow, and a beginner will not know that IDEs can be fast, so they will not cringe every time it lags
M
#include<iostream> using namespace std; int fact(int x){ if(x<=1){ return 1; } return x*fact(x-1); /// factorial formula is n! = n * (n-1) } int main(){ int a; cout<<"enter the number for finding fact"<<endl; cin>>a; cout<<"the fact is "<<fact(a)<<endl; }
M
code works but... what makes the code stop if return is bringing 1
M
how if loop is working here... can someonce to the tracing for me
klimi
ye, it return 1 but it doesn't call another function the other return calls another function
finch
How can i add /Zc:__cplusplus to msvc property panel, using lua script?
Divyanshi
Hey How can I make c++ program to find second largest no. without using arrays
Divyanshi
Ok
Ludovic 'Archivist'
Hey How can I make c++ program to find second largest no. without using arrays
Make a range (something with begin and end that return iterators) and use nth_element from the algorithm header. You should have something like nth_element(number_range.begin(), number_range.end(), 1)
Ludovic 'Archivist'
(your range must store the values somewhere)
Ludovic 'Archivist'
(because nth_element will modify the content of the container)
Anonymous
Hey How can I make c++ program to find second largest no. without using arrays
If you don't wanna use some array like data structure to store the numbers, and directly calculate it by taking input repeatedly inside a loop, just make two variables, max1, max2, set both to INT_MIN, if you encounter a number greater than max1, store max1 in max2, store that number in max1. If your number is not greater than max1 but greater than max2, store it in max2. max2 will now contain the second largest number.
Divyanshi
Ok , thanks!!
Kriss
I wrote this code in c++ while solving a challenge, consisting of while loop and if -else statement and it doesn't passes because it's exceeding the time limit, I don't yet studied DSA concept like time complexity or algorithm, Can someone give me hint or any idea what to learn to solve the problem.
mito
I wrote this code in c++ while solving a challenge, consisting of while loop and if -else statement and it doesn't passes because it's exceeding the time limit, I don't yet studied DSA concept like time complexity or algorithm, Can someone give me hint or any idea what to learn to solve the problem.
maybe you have to approach the problem in a different way to solve it within the given time constraints. I have also had this time limit exceeded kinda problem when I was solving a problem on HackerRank, so I just had to think and implement a solution completely in a different way to my previous solution.
mito
Sometimes, when you're really stuck, just look at the solution of others and understand it.
Serkan
Hi Folks, at one of api person wants to reach source_variable_adress. I saw an example that uses like this. example_function( (uint32_t)source_variable ); I am confused, why we type (uint32_t)source_variable? What is it? Why we didn't gave the address with &source_variable? by the way, it's in embedded application if that matters. with GNU C Compiler (GCC)
Mustafo
for(;;) if (iteration == 10) break; cout << "Введите число: "; cin >> currentInput; if (currentInput < 0) continue; input_numbers[iteration] = currentInput; error: 'continue' statement not in loop statement
Notaxmar
Notaxmar
How do you use C for hacking. How do you even start
Anonymous
M
suppose I wrote a program for printing a variable....but I want to see how c++ compiler is interpreting the value of variable is there any software for it
M
No bro I want how the program is flowing and how the variable is changing its value
M
Wait a min