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

struct Point
{
    
double x, y;
};

bool line( Point a, Point b, Point c )
{
    
return ( b.x- a.x )* ( c.y- b.y )== ( b.y- a.y )* ( c.x- b.x );
}

bool none( Point a, Point b, Point c, Point d )
{
    
return ( b.x- a.x )* ( d.y- c.y )== ( b.y- a.y )* ( d.x- c.x );
}

Point intersection( Point u1, Point u2, Point v1, Point v2 )
{
    Point ret
= u1;
    
    
double t= ( ( u1.x- v1.x)* ( v1.y- v2.y )- ( u1.y- v1.y) * ( v1.x- v2.x ) )
              
/ ( ( u1.x- u2.x )* ( v1.y- v2.y )- ( u1.y- u2.y)* ( v1.x- v2.x) );
              
    ret.x
+= ( u2.x- u1.x )* t;
    ret.y
+= ( u2.y- u1.y )* t;
    
    
return ret;
}

int main()
{
    
int test;
    scanf(
"%d",&test);
    
    puts(
"INTERSECTING LINES OUTPUT");
    
while( test-- )
    {
        Point a, b, c, d;
        scanf(
"%lf %lf %lf %lf %lf %lf %lf %lf"&a.x,&a.y,&b.x,&b.y,
               
&c.x,&c.y,&d.x,&d.y );
               
        
if( line( a, b, c ) && line( a, b, d ) ) puts("LINE");
        
else if( none( a, b, c, d ) ) puts("NONE");
        
else
        {
            Point t
= intersection( a, b, c, d );
            printf(
"POINT %.2lf %.2lf\n", t.x, t.y );
        }
    }
    puts(
"END OF OUTPUT");
    
    
return 0;
}
posted on 2008-12-07 13:38 Darren 阅读(145) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理