游客 Signup | Login
中文 | En

1580 - 重载运算符

建立一个角类,在这个类中重载减号运算符角度相减,并实现求出角度的正弦值的函数

Input

输入第一行为样例数m,接下来有m行每行两个整数表示角度。

Output

输出m行,表示两角相减的正弦值,保留小数点后两位。

Examples

Input

1
60 30

Output

0.50

Solution C

#include<stdio.h>
#include<math.h>

int main(){
	int n,i;
	double a,b,s;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf",&a,&b);
		s=a-b;
		s=s*3.1415926/180;
		s=sin(s);
		printf("%.2lf\n",s);
	}
	return 0;
}

Solution C++

#include <iostream>
#include <math.h>
#include <cstdio>
using namespace std;

const double pi = acos(-1.0);

class angle
{
    int X;
public:
    double xsin();
    angle() {};
    angle(int x)
    {
        X=x;
    }
    angle operator- (angle c);
};
angle angle::operator- (angle c)
{
    return angle(X-c.X);
}
double angle::xsin()
{
    double x=X*pi/180;
    return sin(x);
}
int main()
{
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    int p, q, t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d %d", &p, &q);
        angle a(p),b(q),d;
        d=a-b;
        printf("%.2f\n", d.xsin());
    }
    return 0;
}

Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题