任你用什么数学方法,加减乘除、平方开方、指数对数、勾股定理、微分积分、复数运算等方法,找出一个万能公式,让正数变1、负数变-1,零还是0
但是,不能用任何条件句
383 1
214 1
82 1
7 1
1 1
0 0
-9 -1
-82 -1
-99 -1
再补充一下,不要用什么sign取符号或位运算等方法,还是那句话,用数学方法
供参考:
#include<stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
n = (n*3)%abs((abs(n)*3-1));
printf("%d\n",n);
return 0;
}
int item = int.Parse(Console.ReadLine());
Console.WriteLine(Math.Round(item / Math.Abs(item+ 1/9d)));
这些数和 1 && 运算
有那么点意思了。还不够完善,数字太大结果会出问题。
#include <stdio.h>
#include <math.h>
int main()
{
int n, r;
while (n != 9999)
{
scanf("%d", &n);
r = -n & -1L;
r /= sqrt(n * n);
r = -r * (n || 0);
printf("%d %d\n", n, r);
}
return 0;
}
```
#include<math.h>
int getSign(double num){
double a = atan(num)*0.5; // a的范围(-1,1)
return ceil(a) + floor(a); // 向上取整加向下取整
}
```c++
int func(int b) {
__try
{
return abs(b) / b;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return 0;
}
}
```