This is the link to my solution. I’m getting the expected output as per the example test case submitted.
try using #include<string>
, some compilers have pre-included some of the header files
Pay attention to compiler warnings!
[simon@simon-laptop][06:45:36]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh
Compiling prakashaditya-SWPDGT.cpp
+ g++ -std=c++14 prakashaditya-SWPDGT.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
prakashaditya-SWPDGT.cpp: In function ‘int main()’:
prakashaditya-SWPDGT.cpp:104:29: warning: ‘numbers[2]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
int ans1 = num1 + numbers[2];
~~~~~^~~~~~~~~~~~
prakashaditya-SWPDGT.cpp:106:29: warning: ‘numbers[1]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
int ans3 = num3 + numbers[1];
~~~~~^~~~~~~~~~~~
prakashaditya-SWPDGT.cpp:105:29: warning: ‘numbers[0]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
int ans2 = num2 + numbers[0];
~~~~~^~~~~~~~~~~~
+ set +x
Successful
[simon@simon-laptop][06:45:38]
[~/devel/hackerrank/otherpeoples]>echo "1
5 4" | ./a.out
terminate called after throwing an instance of 'std::out_of_range'
what(): stoi
Aborted (core dumped)
Edit:
Oh - this thread is a year old XD
1 Like