123 456 789

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <bits/stdc++.

h>
using namespace std;
ofstream g("list.out");
vector<int> bif(10, 0), a(10);
struct hash_pair
{
int operator()(const pair<int, int> &p) const
{
auto hash1 = hash<int>{}(p.first);
auto hash2 = hash<int>{}(p.second);
return hash1 ^ hash2;
}
};
unordered_map<pair<int, int>, bool, hash_pair> ma;
int rez = 0;
bool verif();
void afis();
void back(int k);
int main()
{
back(1);
g << rez;
return 0;
}
bool verif()
{
int n1 = (a[1] * 10 + a[2]) * 10 + a[3];
int n2 = (a[4] * 10 + a[5]) * 10 + a[6];
int n3 = (a[7] * 10 + a[8]) * 10 + a[9];
if (n1 > n2)
swap(n2, n1);
if (!ma[make_pair(n1, n2)])
return n1 + n2 == n3;
else
return 0;
}
void afis()
{
int n1 = (a[1] * 10 + a[2]) * 10 + a[3];
int n2 = (a[4] * 10 + a[5]) * 10 + a[6];
int n3 = (a[7] * 10 + a[8]) * 10 + a[9];
if (n1 > n2)
swap(n2, n1);
ma[make_pair(n1, n2)] = 1;
rez++;
g << n1 << '+' << n2 << '=' << n3 << '\n'
<< '\n';
}
void back(int k)
{
if (k <= 9)
for (int j = 1; j <= 9; j++)
if (!bif[j])
a[k] = j, bif[j] = 1, back(k + 1), bif[j] = 0;
else
true;
else if (verif())
afis();
}

You might also like