Bitwise OR Summary
PHP
Medium
5 views
Problem Description
Given n numbers, print bitwise OR of them.
Input Format
First n. Next line n ints.
Output Format
One integer.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0; $n=intval($tokens[$i++] ?? 0);
$ans=0;
for($k=0;$k<$n;$k++) $ans |= intval($tokens[$i++] ?? 0);
echo $ans;
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!