An unexpectedly difficult problem

Правка en23, от tredsused70, 2023-01-28 00:38:18

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

.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en24 Английский tredsused70 2023-01-28 00:38:27 5 (published)
en23 Английский tredsused70 2023-01-28 00:38:18 1028 (saved to drafts)
en22 Английский tredsused70 2023-01-27 23:56:48 0 Tiny change: 'striction?\n' -> 'striction? There is no restriction to time complexity\n'
en21 Английский tredsused70 2023-01-27 22:43:33 0 (published)
en20 Английский tredsused70 2023-01-27 22:41:31 4 Tiny change: 'blem of this one.\n\nG' -> 'blem of that one.\n\nG'
en19 Английский tredsused70 2023-01-27 22:39:12 46
en18 Английский tredsused70 2023-01-27 22:34:44 0
en17 Английский tredsused70 2023-01-27 22:34:44 207
en16 Английский tredsused70 2023-01-27 22:29:54 2
en15 Английский tredsused70 2023-01-27 22:29:23 122
en14 Английский tredsused70 2023-01-27 22:23:31 191
en13 Английский tredsused70 2023-01-27 22:14:54 5 Tiny change: 'h that $c != b$, and b' -> 'h that $c \ne b$, and b'
en12 Английский tredsused70 2023-01-27 22:11:37 28
en11 Английский tredsused70 2023-01-27 22:11:06 20
en10 Английский tredsused70 2023-01-27 22:10:01 256
en9 Английский tredsused70 2023-01-27 22:00:12 51
en8 Английский tredsused70 2023-01-27 21:58:18 13
en7 Английский tredsused70 2023-01-27 21:56:46 159 Tiny change: 'solution">\n~~~~~\n#in' -> 'solution">~~~~~\n#in'
en6 Английский tredsused70 2023-01-27 21:51:24 66
en5 Английский tredsused70 2023-01-27 21:50:44 49 Tiny change: '\n\n<spoil' -> '\n~~~~~\nint n = 1;\ncout << n << "\n";\n~~~~~\n\n\n<spoil'
en4 Английский tredsused70 2023-01-27 21:50:07 5
en3 Английский tredsused70 2023-01-27 21:48:58 25
en2 Английский tredsused70 2023-01-27 21:47:57 256
en1 Английский tredsused70 2023-01-27 21:46:13 122 Initial revision (saved to drafts)