One Comment

  1. Exista o problema cu acest algoritm. In cazul in care valorile introduse corespund unor puncte coliniare (de ex 1,1 / 2,2, / 3/3 , 4/4) ploblema retunreaza “DA”, cand ar trebui sa returneze nu. Acesta este algoritmul la care m-am gandit eu.
    #include
    using namespace std;

    int x[4],y[4],i;

    void interschimbare(int a, int b)
    {
    int aux=x[a];
    x[a]=x[b];
    x[b]=aux;
    aux=y[a];
    y[a]=y[b];
    y[b]=aux;
    }
    void ordonare()
    {
    for(i=1;i<4;i++)
    if(x[i]<x[0] || y[i]<y[0])
    interschimbare(0,i);
    for(i=0;ix[2] || y[i]>y[2])
    interschimbare(2,i);
    }
    void afisare()
    {
    for(i=0;i<4;i++)
    cout<<x[i]<<' '<<y[i]<<endl;
    }

    int dist(int xa, int ya, int xb, int yb)
    {
    return (xb-xa)*(xb-xa)+(yb-ya)*(yb-ya);
    }
    int main()
    {
    int ok=1;
    for(i=0;i>x[i]>>y[i];
    cout<<endl;
    ordonare();
    afisare();
    int pd=dist(x[0],y[0],x[1],y[1]);
    for(i=0;i<=2;i++)
    if(pd!=dist(x[i],y[i],x[i+1],y[i+1])) {ok=0;}
    if(ok==1 && dist(x[0],y[0],x[2],y[2])==2*pd && dist(x[1],y[1],x[3],y[3])==2*pd )
    cout<<"DA";
    else cout<<"NU";
    }

    3

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *