Hi, Can anybody tell me what exactly are we suppose to find in problem RECTCNC ?
So far I understood, we have to find the number of rectangles in a co-ordinate system which I am perfectly getting. Still I got “wrong answer” reply when I submitted the code.
Here is my code.
/*#####################################################################################################
# TO FIND THE NUMBER OF RECTANGLES PRESENT IN A CARTESIAN CO-ORDINATE SYSTEM WHERE POINTS ARE GIVEN #
# AND NO TWO CO-ORDINATES HAVE SAME ABSCISSA #
# #
# PROGRAM BY-: AMRUTANSU GARANAIK #
#####################################################################################################*/
#include<stdio.h>
#include<stdlib.h>
main()
{
printf("Enter the number of co-ordinates and press RETURN key....\nThen input the co-ordinates (x,y)\nNo three co-ordinates should have same abscissa\n\n");
int n; //total inputs
scanf("%d",&n);
int x[n],y[n];
int i,j,k,l;
for(i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
int count; //To count number of co-ordinates with same abscissa
for(i=0;i<n;i++)
{
count=1; //First value is 1 as we take one abscissa and compare it with others..first abscissa makes count 1
for(j=i+1;j<n;j++)
if(x[i]==x[j])
count++;
if(count>2) //Checks if three co-ordinates or more have same abscissa
{
printf("Invalid input");
exit(1);
}
}
int rec_count=0; //Number of rectangles before counting begins
for(i=0;i<n;i++) //Counting the number of rectangles
for(j=0;j<n;j++)
if(x[i]==x[j])
for(k=i+1;k<n;k++)
for(l=k+1;l<n;l++)
if((x[k]==x[l])&&((y[i]==y[k])&&(y[j]==y[l])))
rec_count++;
printf("Number of rectangles = %d",rec_count);
}