We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Both my code and the top two codes in discussions are terminated due to timeout. I don't know how to reduce the runtime anymore. Could anyone successfully solving this problem point out the pitfalls in my code? The version 1 of the following code is my code. The version 2 is quoted from Discussions.
// Version 1 - Phoenix(me)template<classT>classAddElements{Te1;public:AddElements(Targ){e1=arg;}Tadd(Te2){returne1+e2;}};template<>classAddElements<string>{stringe1;public:AddElements(stringstr){e1=str;}stringconcatenate(stringe2){returne1+e2;}};// Version 2 - kk65g3template<classT>classAddElements{public:Telement;AddElements(Ti){element=i;}Tadd(Ti){returnelement+i;}private:};template<>classAddElements<string>{public:stringelement;AddElements(stringi){element=i;}stringconcatenate(stringelement2){returnelement+element2;}private:};
The timeout error makes me confused whether my code is right.Thanks for your advice that uses c++ instead of c++14,but I still want to know why?Is it the compiler problem?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
C++ Class Templates
You are viewing a single comment's thread. Return to all comments →
Both my code and the top two codes in discussions are terminated due to timeout. I don't know how to reduce the runtime anymore. Could anyone successfully solving this problem point out the pitfalls in my code? The version 1 of the following code is my code. The version 2 is quoted from Discussions.
use C++ instead of C++14; otherwise, run the following before main using global variable + class constructor:
The timeout error makes me confused whether my code is right.Thanks for your advice that uses c++ instead of c++14,but I still want to know why?Is it the compiler problem?