not very easy to understand
Maybe because it was just a snippet....
Here is the whole code!....to annoy everyone...
Code:
#include<iostream>
#include<vector>
#include<array>
using namespace std;
array<int,3> itotr(int); //int to triad row
typedef vector<array<int,3>>::iterator VI;
class Tr //triad
{
public:
array<int,3> v1;
array<int,3> v2;
array<int,3> v3;
void disp()
{
cout<<endl;
cout<<v1[0]<<v1[1]<<v1[2]<<endl;
cout<<v2[0]<<v2[1]<<v2[2]<<endl;
cout<<v3[0]<<v3[1]<<v3[2]<<endl;
}
};
int main()
{
vector<Tr> storage;
Tr temp;
vector<array<int,3>> st[10];
int c,mc(0);
for(c=10;c*c<1000;c++)
{
st[(c*c)/100].push_back(itotr(c*c));
}
for(c=10;c*c<1000;c++)
{
temp.v1=itotr(c*c);
for(VI it1=st[temp.v1[1]].begin();it1!=st[temp.v1[1]].end();it1++)
{
temp.v2=*it1;
for(VI it2=st[temp.v1[2]].begin();it2!=st[temp.v1[2]].end();it2++)
{
temp.v3=*it2;
if(temp.v2[2]==temp.v3[1])
{
mc++;
storage.push_back(temp);
}
}
}
}
for(vector<Tr>::iterator it3=storage.begin();it3!=storage.end();it3++)
{
(*it3).disp();
}
cout<<endl<<"Total: "<<mc;
cin.get();
return 0;
}
array<int,3> itotr(int x)
{
array<int,3> v;
v[0]=x/100;
v[1]=(x/10)%10;
v[2]=x%10;
return v;
}
Any criticism? ___except for the fact that I'm scared of 2d arrays...and made the Tr class to make things easier for this small case___