zoukankan      html  css  js  c++  java
  • Rectangles

    Input
    Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).
     
    Output
    Output For each case output the area of their intersected part in a single line.accurate up to 2 decimal places.
     
    Sample Input
    1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.00 5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50
     
    Sample Output
    1.00 56.25
     
     
     

    #include<stdio.h>

    float deal(float k,float xy[])
    {
        if( xy[0] > xy[1] )
        {
            float t = xy[0];
            xy[0] = xy[1];
            xy[1] = t;
        }
        if( xy[2] > xy[3] )
        {
            float t = xy[2];
            xy[2] = xy[3];
            xy[3] = t;
        }
        if( xy[1] <= xy[3] )
        {
            if( xy[1] <= xy[2] )
            {
                return 0;
            }
            else
            {
                if( xy[0] > xy[2] )
                {
                    return xy[1] - xy[0];
                }
                else
                {
                    return xy[1] - xy[2];
                }
            }
        }
        else
        {
            if( xy[3] <= xy[0] )
            {
                return 0;
            }
            else
            {
                if( xy[2] >= xy[0] )
                {
                    return xy[3] - xy[2];
                }
                else
                {
                    return xy[3] - xy[0];
                }
            }
        }  
    }


    int main()
    {
        float x[4],y[4];
        while(scanf("%f%f",&x[0],&y[0]) == 2 )
        {
            int i;
            for( i = 1; i < 4; i++ )
            {
                scanf( "%f%f", &x[i], &y[i] );
            }
            float len = deal( len, x );
            float wid = deal( wid, y );
            printf( "%.2f\n", len*wid );
        }
        return 0;
    }
            

  • 相关阅读:
    asp.net中Session过期设置方法
    SQL server的一道入门面试题背后的思考
    SQL Server 2008中SQL应用之-“阻塞(Blocking)”
    win2003+vs2010下安装asp.net MVC3正式版失败经历
    WinForm下ComboBox设定SelectedValue总结
    SQL Server 2008中的代码安全(四):主密钥
    【译】SQL Server误区30日谈Day12TempDB的文件数和需要和CPU数目保持一致
    西雅图SQL PASS之旅
    【译】SQL Server误区30日谈Day10数据库镜像在故障发生后,马上就能发现
    Ado.net的连接池
  • 原文地址:https://www.cnblogs.com/zsj576637357/p/2290075.html
Copyright © 2011-2022 走看看