Блог пользователя tredsused70

Автор tredsused70, история, 16 месяцев назад, По-английски

Hi, I was solving this problem a few minutes ago, and the following problem is a subproblem of that one.

Given integer $$$n$$$, $$$ n \ge 3$$$, and array $$$a$$$ consisting of $$$n - 1$$$ integers, all of them are equal to some value $$$b$$$. Later, some integer $$$c$$$, such that $$$c \ne b$$$ is selected and inserted into the array $$$a$$$ at random position. By given $$$n$$$ and $$$a$$$ find $$$c$$$.

This problem itself isn't so difficult, but with a certain restriction I couldn't solve it. The restriction is folowing: you can't use $$$if$$$ and ternary operators in any way.

I came up with the solution, that calls $$$if$$$ only one time.

my solution

Can you solve this problem with the given restriction?

UPD: In the comments there is one of the solutions, and I've also came up with one.

my final solution

BledDest's solution is shorter, but mine is easier to understand, at least for me, this is just

spoiler

.

Полный текст и комментарии »

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