Question about "Runtime error (Sigabrt)"

https://www.codechef.com/viewsolution/22473533
here is my code.
I have checked it over and over again but cant find the assertion problem.
can anybody help me?

Reason

Running above code with test case 1 100000000000000000000 on codechef ide shows terminate called after throwing an instance of 'std::out_of_range' what(): stoi

In simpler words, you cannot use atoi for string size >=18.
Why ?? Google c/c++ int overflow and int overflow c++

Thanks for your reply, aryanc403.
However, the constraints of this question said abs(n)<= 10^5 and n does not contain the digit 0.
Are there some other errors in my code?

I have changed my code to make them avaiable for negative numbers, but I still get the same error. I have tested all the numbers that I can imagine(1-99999) and all of them give me an answer not an error. How can I know which testcase give me this error?

From question - |N| denotes the number of digits of N.
So |N|ā‰¤10^5 => No of digits of Nā‰¤10^5.
Therefore, 1 100000000000000000000 is a valid test case.
Inferring abs(n)<= 10^5 in this question is wrong.

You can confirm this by adding -
if(k>10) while(1);
If you get Time Limit Exceeded verdict, then k is indeed more than 10 for some test cases.

thank you soooo much aryanc403. it is so sad for me to know the error comes from my misunderstanding about symbols, but I do believe that, with your help, I will not make the same mistake. Thanks again for your patience and help.

1 Like