« first day (371 days earlier)      last day (2706 days later) » 

09:50
Hey! I was doing this problem I wasn't able to make the solution faster so i referred to the editorial, I would really appreciate if anyone can explain me the editorial solution.
#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n , m , k , t;

    cin >> t;

    while(t--){

        cin >> n >> k;

        if(k > 81){                 // invalid case

            cout << "-1\n";
            continue;
        }

        int start = k / 9 + (k % 9 != 0);       // first number

        int order = k % 9;                  // order of the second number
        if(order == 0) order = 9;

        int second = order;             // second number

        if(second <= start) second--;
^^ solution that needs to be explained.
nwp
nwp
10:05
@SaubhagyaSrivastava you should really consider quitting that garbage site
They are teaching you C with cout which will take you years to unlearn.
Ven
Ven
lol
it's actually true
@nwp
what you suggest for competetive ?
competitive?
nwp
nwp
@SaubhagyaSrivastava There is no such thing as competitive programming. Go write a game or something. Learn how to use libraries effectively. Notice how after 2 weeks you don't understand your own code and how structuring it better helps with that.
Ron
Ron
10:54
Can someone please clarify what is the meaning of the syntax in this question?
What is this trickery (X*)::operator new(sizeof(X));?
Placement new, apparently...
 
3 hours later…
13:29
@Ron Unfortunately, no it's not. This is invoking ::operator new to allocate some raw memory (that's the ::operator new(sizeof(X)) part), then using a C-style cast (the (X *) part) to treat that memory as an X.
wow, I was tricked too
I initially parsed this as accessing the member function of X*, but that obviously wouldn't work
 
3 hours later…
16:59
If I have class foo that has member variable of class bar with its own destructor, do I explicitly call the destructor method of bar from foo's destructor?
17:16
no
I'm pondering this type of use case (which faults nicely). What is the way to handle the memory deallocations so that `b` that holds member `a` inherits the responsibility and the destructor won't get called twice?

#include <stdio.h>
#include <stdlib.h>

struct A {
int *arr;
A(size_t elems) : arr(new int[elems]) {};
~A()
{
puts("In A's destructor!");
delete [] arr;
}
};

struct B {

struct A member;

B(struct A a): member(a) {}
};

int main()
{
struct A a(10);
struct B b(a);
}
nwp
nwp
17:43
@ELEC this doesn't do what you want to do at all
double-delete -> UB
In short never use new.
In this case (and many others) use std::vector instead.
18:09
@ELEC you solve this by using Rule of Zero
in this case, by using std::vector
 
1 hour later…
19:32
Hello everyone

I was wondering whether someone could tell me whether what I am doing is good practice.

I hava one class called MainWindow which is in charge for the GUI. When its constructor gets called the gui is actually setup. I instantiate this class from a source file called main.cpp
Now I have another class with code for image processing and computer vision.
Now the question is should I instantiate the computervision class from my main.cpp or from the MainWindow's constructor?
 
1 hour later…
M-J
M-J
20:35
Hi, can anyone please inform me why i'm seeing this error in VS2015? (I've included the vector library already):
This one is really weird. I've been using vectors very often previously. I even made a new project and copy-pasted my whole code in it, but the error remained. I also restarted my laptop. :|
@M-J something is doing #define vector Vector (note the syntax highlighting of the word vector - it's purple, which means it's a macro)
find out what
M-J
M-J
@milleniumbug Thanks. I take a look now.
@milleniumbug Aah, you're right. Thanks.
I think this may be the first time ever that posting a screen shot actually provided extra information that was useful in solving the problem (instead of being a handicap).
3
@milleniumbug this is why I hate macros, there is actually a symbol bug in the windows headers that can never be fixed because of this sort of squatting.
20:50
@trilolil In a windowing system you'd typically use something like model-view-controller (MVC), in which case the vision would probably belong as part of your model.
^+1
@JerryCoffin blimey
21:24
Hey, can any1 have a look at this and let me know why does this not work? I'm lost :- ( pastebin.com/P7pkQ11D
Trying to rad file here :x
Meh needed !ifile.eof() ()
@Dariusz Only you actually don't want to use either one. Try while (getline(ifile, fileData)) /* process a line */
ehh still not working
@Dariusz while (!foo.eof()) (nearly) never really does.
hehe
how do I put the lines in to string?
@Dariusz Do you want all the lines in one string, or each line in its own string?
21:32
not sure, Its json file so I guess they can be in 1 line?
    string fileData;
    string outData;
    cout<<path.toStdString()<<endl;
    ifstream ifile(path.toStdString());
    if (ifile) {
        cout<<"LIOL"<<endl;
        ifile.open(path.toStdString());

        while(getline(ifile,fileData))
        {
            cout<<fileData;
        }
        ifile.close();

        cout<<outData<<endl;
        cout<<fileData<<endl;

    }
the 2 last couts output nothing :- (
nwp
nwp
@Dariusz outData is never set. And fileData probably gets set to "" because the last line is empty.
humh
In that case, I'd typically use something like this:

std::ifstream in(filename);
std::stringstream buffer;
buffer << in.rdbuf();
// now `buffer.str()` contains the whole file
wow
how do you then put the buffer in to string?
eh nvm
google ftw
std::string allTheFileContents = buffer.str();
21:37
yup
yay that works :D
thank you!
Ron
Ron
@JerryCoffin Appreciate.
@Ron Surely. Note that it works well for reasonably small files, but (typically) slows down a fair amount if a file is really big (e.g., tens of megabytes or more).
JSON files large enough to cause it a major problem are fairly unusual though.
22:01
Would you say this is ok to save file to json format? or I need to somehow to dumps.json  it ?

    ofstream myfile(path.toStdString().c_str());
    if (myfile.is_open()) {
        myfile << data;
        myfile.close();
    }
If your compiler's reasonably current, you shouldn't need the `.c_str()`. If the file didn't open, writing to it is harmless. It'll close automatically when it goes out of scope.

ofstream myfile(path.toStdString());
myfile << data;
thanks
 
1 hour later…
23:04
@Dariusz Don't write your own code, uscilab.github.io/cereal

« first day (371 days earlier)      last day (2706 days later) »