Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя levi.ackerman1732

Автор levi.ackerman1732, история, 4 года назад, По-английски

Hello all

1201A - Important Exam

My solution, was to store the number of responses(among A,B,C,D,E) for each question and choose the maximum among them and multiply with the marks awarded. I am getting a Runtime error. I am not able to figure out why.

The part of code where it's failing is:

s is string, j is the question number

	temp = (int)(s[j]-'A');

	v[j][temp]++;

I have encountered this problem quite a few times, but have avoided every time somehow. Please do let me know what is wrong with this.

My solution: 70953260

I am extremely sorry if I am asking something that is fairly obvious. Thank you for your time.

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

You are accessing the jth index of v where j < m. You declared v to have n elements. But there is no restriction that says m <= n. So what happens if m > n? Undefined behavior.