I want to count All the square and rectangle between the coordinates by the backtracking Algorithm and I need help to complete my code to Do that
The Table will be Like :
if I Enter the points (1,1),(1,2),(2,1),(2,2),(3,1),(3,2),(5,2),(3,3)..
___1 2 3 4 5 6 7
1 * * * 0 0 0 0
2 * * * 0 * 0 0
3 * * * 0 0 0 0
Here supposed to be : the count of the squares=2 "the first is formed by the points (1,1)&(1,2)&(2,1)&(2,2), the second by (1,1)&(3,1)&(1,3)&(3,3) "
and Rectangle=1 "it is (1,1)&(3,1)&(1,2)&(3,2)
What I have tried:
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <iterator>
using namespace std;
const size_t size=20;
char table[size][size];
void table_clear(void){
for(int v = 0; v<size; ++v)
for(int h = 0; h<size; ++h)
table[v][h]=' ';
}
void table_put(pair<int, int> p){
int v = p.first;
int h = p.second;
table[v-1][h-1] = '*';}
void table_disp(){
cout << "***";
for(int i=0; i<size;++i){
cout << setw(3) << i + 1;
}
cout << "\n" << endl;
for(int i=0;i<size;++i,cout<<endl){
cout << setw(3) << left << i + 1;
for(int j=0;j<size;++j){
cout << setw(3) << right << table[i][j];
}
cout<<endl;
}
}
int main(){
vector<pair<int,int> > v;
pair<int, int> end(99,99);
pair<int, int> XY;
cout << "Enter each cell in first colony use row space column Enter format, 3 4, for example.\n";
cout << "Enter 99 99 to end entries." << endl;
while(1){
int x,y;
cin >> y;
cin >> x;
XY = make_pair(x,y);
if(XY == end)
break;
v.push_back(XY);
}
cout<<"\n\n";
table_clear();
for(vector<pair<int,int> >::const_iterator iter = v.begin();iter != v.end(); ++iter ) {
table_put(*iter);
}
table_disp();
}
[Update]
It is calculated to be a square or a rectangle in the case if the four angles within the Points, which entered=* and !=0."Regardless of the fact that inside the square or rectangle containing 0"
Like:
__1 2 3 4 5
1 * 0 * 0 *
2 0 0 * 0 *
3 * 0 * * 0
Here is squares=1 (1,1)&(3,1)&(1,3)&(3,3) and Rectangle =2 the first (3,1)&(3,2)&(5,1)&(5,2) the second (1,1)&(3,1)&(1,3)&(3,3) 2) the count beginning from the first nearest point to (1,1) to the End of the Table in Backtracking Method.