## C and C++

Moderators: None (Apply to moderate this forum)
Number of posts: 94715

This Forum Only

Match Shapes Posted by rkgamateur on 26 Jan 2010 at 9:42 AM
In this problem, you are given a set of points. By combining these points in given order by lines you get a shape. You need to check whether it matches with S shape which could be rotated by 90, 180, 270 degree.

Depending on the type of shape it matches you need to return that number. For example if it matches with shape 1 of the diagram return 1. If it doesn't matches any return 0.

The prototype of the function is:

int matchshapes(struct point p[],int size); where p is given array of points, size represents array size

Constraints

A given set of points that makes S shape has its all lines that are parallel either x or y axis.
Example 1

Input
p[0] = (0,0)
p[1] = (1,0)
p[2] = (1,1)
p[3] = (1,2)
p[4] = (0,2)
p[5] = (0,3)
p[6] = (1,3)
p[7] = (2,3)
Output
Function "matchshapes" returns 2
Explanation : The given set of points represents 2nd diagram shown in the figure <a href="http://lh3.ggpht.com/_zsPAx1bnnIQ/S18Bco0JzUI/AAAAAAAAAB4/ps7BJ6d_3MI/shapes.gif">Click Here</a> i.e. function matchshapes will return 2.

Example 2

Input
p[0] = (0,0)
p[1] = (1,0)
p[2] = (1,1)
p[3] = (0,1)
p[4] = (0,2)
p[5] = (0,3)
p[6] = (1,3)
p[7] = (2,4)
Output
Function "matchshapes" returns 0

Someone please help me out in this. u can provide the code or any ideas on this.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic