It used to be a good practice to write code like this: int var = 0, var1 = 0; //declare variables outside the loop not to create them every time we go into for auto var2 = somefunc(/*some params*/); for (int i = 0, size = vec.size(); i < size; ++i) { //do some calculation, ..
Category : coding-style
I want to store element and it row and column in min heap priority_queue <pair<int,pair<int,int>>, vector, greater>pq; Source: Windows Que..
like for example: string = "me" def print_str(n): print(n) string.print() i want to do something like this Source: Windows..
I’ve written this code but i guess it is so complex and it is hard to read it. There is about 500 line like that.. I’m creating a chart using these. I have series array which occurs 160 elements. And queue as well How can i clean it. Im ashamed for asking it. if(item->parent() == ..
void staircase(int n) { for(int i = 1 ; i <= n ; i++) { string h(i,’#’); string s(n-i,’ ‘); cout<<s<<h<<endl; }} Please explain the two lines in the for loop. Can we declare like string h(i,’#’); in strings? Does it means filling the ith position in the string with "#" ? Source: Windows Questions ..
In sports coding many a times while giving assessment in which question related to sports coding are given programming language is restricted to Java. So recently I faced a lot of problems while submitting solution to simple question because I have never used Java in competitive programming. I wanted to know if Java has a ..
Say I create some function in my class: bool isRisingEdge() { return current && !last; } I also want to generate overloaded versions of this function that accompany it. For the sake of example, let’s say I need to overload it with just two different types; the same two types each time. Each overload first ..
What is significance of return statement here? [ question : N_queen problem ] When I call without using return, the function works. But it doesn’t work when I use return statement in recursion call [I have mentioned in the code]. Please explain and if possible can you please explain by tracing out the calls(i.e, how ..
Ive build a loop to sum all the working hours using do.. while and for loops. But i seemed to can’t get the total hours right.my output didnt show the right amount of total hours .can u help me show how to make it calculate the total hours correctly? #include <iostream> using namespace std; int ..
I Just Have A Question How Can Use Struct Pointers with Designated Initialization for example I know how to init the struct using the dot operator and Designated Initialization like person per = { .x = 10,.y = 10 }; but If I want to do it with struct pointer ? I made this but ..
Recent Comments