1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// Vampire.cpp : main project file.
#include <iostream>
#include <fstream>
using namespace std;
//--------------------------------------------------------------------
void Vampire(ofstream& fr,int sk, int a, int b, int c, int d);
// --------------------------------------------------------------------
int main()
{
int a, b, c ,d; // digits of the number with 4 counts
int sk;
ifstream fd("Duomenys.txt");
ofstream fr("Rezultatissimo.txt");
fr << "A program 'Vampire Counts' starts." << endl;
fr << "The main number: ";
fd >> sk;
fr << sk << endl;
fr << "Vampire counts: " << endl;
for (sk; sk <= 9999 ; sk++) // Go from 10 to 2000
{
a = sk/1000;
b = (sk/100)%10;
c = (sk/10)%10;
d = sk % 10;
Vampire (fr,sk,a,b,c,d);
Vampire (fr,sk,b,a,c,d);
Vampire (fr,sk,a,b,d,c);
Vampire (fr,sk,b,a,d,c);
Vampire (fr,sk,a,c,b,d);
Vampire (fr,sk,c,a,b,d);
Vampire (fr,sk,a,c,d,b);
Vampire (fr,sk,c,a,d,b);
Vampire (fr,sk,a,d,b,c);
Vampire (fr,sk,d,a,b,c);
Vampire (fr,sk,a,d,c,b);
Vampire (fr,sk,d,a,c,b);
}
fd.close();
fr.close();
cout << "Results are in the file Rezultatissimo.txt" <<endl;
return 0;
}
//----------------------------------------------------
void Vampire(ofstream& fr,int sk, int a, int b, int c, int d)
{
if (sk == (a*10+b)*(c*10+d))
{
fr << sk << " = ((" << a <<" * 10 ) + " << b << ") * ((" << c << " * 10 ) + " << d << ") or [ (" << (a*10+b ) << ") * (" << c*10+d << ") ]" << endl;
cout << sk << " = ((" << a <<" * 10 ) + " << b << ") * ((" << c << " * 10 ) + " << d << ") or [ (" << (a*10+b ) << ") * (" << c*10+d << ") ]" << endl;
}
}
//------------------------------------
|