| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怎么一直wa。。。错哪了??#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
//ifstream cin("aaa.txt");
//ofstream cout("bbb.txt");
int n; cin>>n;
cout<<"INTERSECTING LINES OUTPUT\n";
for(int x1,y1,x2,y2,x3,y3,x4,y4; n--&&cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4; )
{
cout<<fixed<<setprecision(2);
if(x1==x2&&x3==x4) cout<<(x1==x2?"LINE\n":"NONE\n");
else
if(x1==x2&&x3!=x4)
{
double k2=double(y4-y3)/double(x4-x3), b2=double(x4*y3-x3*y4)/double(x4-x3);
cout<<"POINT "<<double(x1)<<' '<<k2*x1+b2<<endl;
}
else
if(x1!=x2&&x3==x4)
{
double k1=double(y2-y1)/double(x2-x1), b1=double(x2*y1-x1*y2)/double(x2-x1);
cout<<"POINT "<<double(x3)<<' '<<k1*x3+b1<<endl;;
}
else
{
double k1=double(y2-y1)/double(x2-x1), b1=double(x2*y1-x1*y2)/double(x2-x1),
k2=double(y4-y3)/double(x4-x3), b2=double(x4*y3-x3*y4)/double(x4-x3);
if(k1==k2) cout<<(b1==b2?"LINE\n":"NONE\n");
else
{
double x=(b1-b2)/(k2-k1), y=(k2*b1-b2*k1)/(k2-k1);
cout<<"POINT "<<x<<' '<<y<<endl;
}
}
}
cout<<"END OF OUTPUT\n";
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator