zhifangzi @ 2021-09-07 23:25:03
#include <iostream>
#include<iomanip>
#include<math.h>
using namespace std;
class point
{
public:
bool set(double a, double b);
point();
point(double x, double y);
double reflex(int deter);
private:
double x, y;
};
double distance(double x1, double x2, double y1, double y2);
int main()
{
point a[3];
for (int i = 0; i <= 2; i++)
{
double x, y;
cin >> x ;
cin >> y;
a[i].set(x, y);
}
double dis=0;
for (int i = 0; i <= 2; i++)
{
if (i <2)
{
dis=dis+distance(a[i].reflex(1), a[i + 1].reflex(1), a[i].reflex(2), a[i + 1].reflex(2));
}
if (i == 2)
{
dis=dis+distance(a[i].reflex(1), a[0].reflex(1), a[i].reflex(2), a[0].reflex(2));
}
}
printf("%.2llf", dis);
return 0;
}
point::point(double a, double b)
{
x = a;
y = a;
}
point::point()
{
x = 0;
y = 0;
}
bool point::set(double a, double b)
{
x = a;
y = b;
return true;
}
double point::reflex(int deter)
{
if (deter == 1)
{
return x;
}
else
{
return y;
}
}
double distance(double x1,double x2,double y1,double y2)
{
double aa = (x1 - x2);
double bb = y1 - y2;
double result = sqrt(aa * aa + bb * bb);
return result;
}
https://picb.cc/image/wbzAzJ 本地运行状况
by zhifangzi @ 2021-09-07 23:31:56
我想骂人, 破案了,最后需要scanf里面写lf而非llf 这个怎么写vs都能出来,洛谷不行,
吐血 一晚上浪费了
附上过了的代码:
#include <iostream>
#include<iomanip>
#include<math.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
class point
{
public:
bool set(double a, double b);
point();
point(double x, double y);
double reflex(int deter);
private:
double x, y;
};
double distance(double x1, double x2, double y1, double y2);
int main()
{
point a[3];
for (int i = 0; i <= 2; i++)
{
double x, y;
cin >> x ;
cin >> y;
a[i].set(x, y);
}
double dis=0;
for (int i = 0; i <= 2; i++)
{
if (i <2)
{
dis=dis+distance(a[i].reflex(1), a[i + 1].reflex(1), a[i].reflex(2), a[i + 1].reflex(2));
}
if (i == 2)
{
dis=dis+distance(a[i].reflex(1), a[0].reflex(1), a[i].reflex(2), a[0].reflex(2));
}
}
printf("%.2llf", dis);
return 0;
}
point::point(double a, double b)
{
x = a;
y = a;
}
point::point()
{
x = 0;
y = 0;
}
bool point::set(double a, double b)
{
x = a;
y = b;
return true;
}
double point::reflex(int deter)
{
if (deter == 1)
{
return x;
}
else
{
return y;
}
}
double distance(double x1,double x2,double y1,double y2)
{
double aa = (x1 - x2);
double bb = y1 - y2;
double result = sqrt(aa * aa + bb * bb);
return result;
}
by ud2_ @ 2021-09-08 00:13:51
所以换个编译器吧。
GCC 的编译警告:
main.cpp: In function 'int main()':
main.cpp:46:18: warning: use of 'll' length modifier with 'f' type character has either no effect or undefined behavior [-Wformat=]
46 | printf("%.2llf", dis);
| ^
main.cpp: In constructor 'point::point(double, double)':
main.cpp:50:31: warning: unused parameter 'b' [-Wunused-parameter]
50 | point::point(double a, double b)
| ~~~~~~~^
by Blackajactic @ 2021-09-08 11:46:15
devc++用吧,vs是vc,不一样的
by 2022fsjh @ 2022-08-05 09:56:06
的确,呵呵