#P8869. [传智杯 #5 初赛] A-莲子的软件工程学

[传智杯 #5 初赛] A-莲子的软件工程学

Background

Under the bombardment of cosmic rays, some of the functions that Lianzi had predefined on her computer were damaged.

For a science student, various software tools are very important in study and research. To restore the normal use of the software on her computer as soon as possible, she needs to rewrite some of these functions quickly.

Problem Description

Specifically, given two integers a,ba, b, with b0b \neq 0 guaranteed, Lianzi wants to implement a function fun(a,b)\operatorname{fun}(a,b) that transfers the sign of bb onto aa.

More precisely, $\operatorname{fun}(a,b)=\operatorname{sgn}(b)\times |a|$, where $\operatorname{sgn}(b)=\begin{cases}1&b>0\\-1&b<0\end{cases}$.

In other words:

  • If bb is positive, then fun(a,b)=+a=a\operatorname{fun}(a,b)=+|a|=|a|.
  • If bb is negative, then fun(a,b)=a\operatorname{fun}(a,b)=-|a|.

Input Format

  • A single line containing two integers a,ba, b.

Output Format

  • A single line containing one integer, the value of fun(a,b)\operatorname{fun}(a,b).
-1 2
1
0 -4
0
-12345 -54321
-12345

Hint

For all testdata, aa and bb are within the range of 32-bit signed integers, and b0b \neq 0.

Translated by ChatGPT 5