Swap Two Numbers (No Temp)

Swap Two Numbers (No Temp)

Easy PHP PHP Variables 19 views
Explanation Complexity

Problem Statement

Two integers a and b are given. Swap them without using a third variable and print the result.

Input Format

One line: a b.

Output Format

One line: swapped_a swapped_b.

Example

5 9
9 5

Constraints

-10^9

Input / Output Format

Input Format
One line: a b.
Output Format
One line: swapped_a swapped_b.
Constraints
-10^9

Examples

Input:
5 9
Output:
9 5

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.