#include <iostream> #include <set> using namespace std;
set<int> unic; int getNum(int a, int b, int c) { return a*100+b*10+c; } void check(int g, int e, int d, int a) { if ((a>d) and (g*a==e*d)) { int temp = g*1000+e; if (unic.find(temp) != unic.end()) return; cout << g<< "/" <<e << "=" << d<< "/" <<a<< "\n"; unic.insert(temp); } }
int main() { // your code goes here int a,b,c,d, e; for (a=1; a<10; a++) for (b=0; b<10; b++) for (c=0; c<10; c++) { if ((b==0) and (c==0)) continue; e = a*100+b*10+c;
for (d=1; d<10; d++) { check( getNum(d,b,c), e, d,a); check( getNum(d,c,b), e, d,a); check( getNum(b,d,c), e, d,a); check( getNum(b,c,d), e, d,a); check( getNum(c,b,d), e, d,a); check( getNum(c,d,b), e, d,a);
check( getNum(d,c,a), e, d,b); check( getNum(d,a,c), e, d,b); check( getNum(a,c,d), e, d,b); check( getNum(a,d,c), e, d,b); check( getNum(c,d,a), e, d,b); check( getNum(c,a,d), e, d,b);
check( getNum(d,b,a), e, d,c); check( getNum(d,a,b), e, d,c); check( getNum(a,b,d), e, d,c); check( getNum(a,d,b), e, d,c); check( getNum(b,d,a), e, d,c); check( getNum(b,a,d), e, d,c); } }
пинг большой
#include <set>
using namespace std;
set<int> unic;
int getNum(int a, int b, int c)
{
return a*100+b*10+c;
}
void check(int g, int e, int d, int a)
{
if ((a>d) and (g*a==e*d))
{
int temp = g*1000+e;
if (unic.find(temp) != unic.end()) return;
cout << g<< "/" <<e << "=" << d<< "/" <<a<< "\n";
unic.insert(temp);
}
}
int main() {
// your code goes here
int a,b,c,d, e;
for (a=1; a<10; a++)
for (b=0; b<10; b++)
for (c=0; c<10; c++)
{
if ((b==0) and (c==0)) continue;
e = a*100+b*10+c;
for (d=1; d<10; d++)
{
check( getNum(d,b,c), e, d,a);
check( getNum(d,c,b), e, d,a);
check( getNum(b,d,c), e, d,a);
check( getNum(b,c,d), e, d,a);
check( getNum(c,b,d), e, d,a);
check( getNum(c,d,b), e, d,a);
check( getNum(d,c,a), e, d,b);
check( getNum(d,a,c), e, d,b);
check( getNum(a,c,d), e, d,b);
check( getNum(a,d,c), e, d,b);
check( getNum(c,d,a), e, d,b);
check( getNum(c,a,d), e, d,b);
check( getNum(d,b,a), e, d,c);
check( getNum(d,a,b), e, d,c);
check( getNum(a,b,d), e, d,c);
check( getNum(a,d,b), e, d,c);
check( getNum(b,d,a), e, d,c);
check( getNum(b,a,d), e, d,c);
}
}
return 0;
}