## Problem 378

Moderator: Board moderators

### Problem 378

I don't know why I'm getting WA.
For this test case I'm getting the same answer from uva.toolkit
Code: Select all
`100 0 4 4 0 4 4 0 5 0 7 6 1 0 2 3 5 0 7 6 3 -6 4 -3 2 0 2 27 1 5 18 5 0 3 4 0 1 2 2 5 0 0 1 1 0 0 1 1 4 0 6 0 1 2 6 9 1 0 5 0 8 5 4 5 1 0 5 0 5 0 1 0 0 1 0 5 0 5 0 1`

My code :
Code: Select all
`#include <stdio.h>int main(void){    int n,x1,x2,y1,y2;    double a1,a2,b1,b2,c1,c2,X,Y; /*Line Eq: ax+by+c=*/    printf("INTERSECTING LINES OUTPUT\n");    scanf("%d",&n);    while(n--)    {        scanf(" %d %d %d %d ",&x1,&y1,&x2,&y2);        if(x1^x2){ /*finding first line eq*/            b1=1.0;            a1 = (double) (y1-y2)/(x2-x1);            c1 = (double) -(a1*x1+y1);        }else{/*x1==x2 -> vertical line*/            a1=1.0; b1=0.0; c1 = -x1;        }        scanf(" %d %d %d %d ",&x1,&y1,&x2,&y2);        if(x1^x2){ /*finding second line eq*/            b2=1.0;            a2 = (double) (y1-y2)/(x2-x1);            c2 = (double) -(a2*x2+y2);        }else{/*x1==x2 -> vertical line*/            a2=1.0; b2=0.0; c2 = -x1;        }        if((a1==a2) &&(b1==b2)){ /*True ->parallel*/            if(c1==c2)printf("LINE\n"); /*Same line*/            else printf("NONE\n");        }        else{ /*Finding the intersection points*/            X = (b2*c1 - c2*b1)/(a2*b1-b2*a1);            if(b1==0)/*Avoiding division for 0*/                Y = (a2*X+c2)/b2;            else                Y = (a1*X+c1)/b1;            if(Y==0)printf("POINT %.2f 0.00\n",X);            else if(X==0) printf("POINT 0.00 %.2f\n",-Y);            else printf("POINT %.2f %.2f\n",X,-Y);        }    }    printf("END OF OUTPUT");    return 0;}`

Rafa3p
New poster

Posts: 5
Joined: Sun Dec 25, 2011 1:32 am

### Re: Problem 378

I changed this:
Code: Select all
`            if(Y==0)printf("POINT %.2f 0.00\n",X);            else if(X==0) printf("POINT 0.00 %.2f\n",-Y);            else printf("POINT %.2f %.2f\n",X,-Y)`

for this:
Code: Select all
`            if(X==0)printf("POINT 0.00");            else printf("POINT %.2f",X);            if(Y==0) printf(" 0.00\n");            else printf(" %.2f\n",-Y);`

And got AC.
I did this because sometimes i was printing "-0.00" instead of "0.00"
Rafa3p
New poster

Posts: 5
Joined: Sun Dec 25, 2011 1:32 am