Swap with XOR

Swap with XOR

Medium PHP PHP Operators 32 views
Explanation Complexity

Problem Statement

Swap two integers using XOR and print them.

Input Format

One line: a b.

Output Format

One line: swapped_a swapped_b.

Example

4 7
7 4

Constraints

0

Input / Output Format

Input Format
One line: a b.
Output Format
One line: swapped_a swapped_b.
Constraints
0

Examples

Input:
4 7
Output:
7 4

Example Solution (Public)

PHP
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$a,$b]=array_map('intval',preg_split('/\\s+/', $inputText));
$a=$a^$b; $b=$a^$b; $a=$a^$b;
echo $a.' '.$b;
?>

Official Solution Code

<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$a,$b]=array_map('intval',preg_split('/\\s+/', $inputText));
$a=$a^$b; $b=$a^$b; $a=$a^$b;
echo $a.' '.$b;
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.