You are not logged in. Please login at www.codechef.com to post your questions!

×

Problem in declaring vector,Runtime error

The link to my code is http://ideone.com/mwwBjl

Why am i getting runtime error. the above code is solution of question https://www.interviewbit.com/problems/smallest-multiple-with-0-and-1/

Thanks in advance.

asked 16 Jul '16, 01:32

buffy20's gravatar image

3★buffy20
5112
accept rate: 0%


the problem is in your multiple function not in declaration.. if you try to run your main only by commenting your multiple function you will see the output "in main"

link

answered 16 Jul '16, 01:54

naksh9619's gravatar image

4★naksh9619
6196
accept rate: 12%

on dev c++, I could even see some chk0 printed.chk0 which are before the assignment flag[val]=1 get printed and after that code stops working.

(16 Jul '16, 02:48) buffy203★
  1. Your multiple function returns an std::string but you haven't used the return value. Though this is not the reason of the runtime error, still it will give a warning.

  2. In line number 16 and 18, you are doing flag[val] = 1, where val = 1 according to your code. However, your vectors are still of size 0, so you are accessing memory out of bounds, which gives you RTE.

Have a look at this code of yours. I have removed the RTE, but have not touched your solution: Corrected code

link

answered 16 Jul '16, 05:49

sahilarora.535's gravatar image

4★sahilarora.535
1235
accept rate: 0%

Got it. Thanks a lot.

(16 Jul '16, 12:53) buffy203★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×525
×231
×73
×6

question asked: 16 Jul '16, 01:32

question was seen: 1,371 times

last updated: 16 Jul '16, 12:53