Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<string>
- #include<math.h>
- #include<fstream>
- int getDigit(int& nIndeks, int& nLiczba)
- {
- return std::stoi(std::to_string(nLiczba).substr(nIndeks-1,1));
- }
- int getNumOfDigits(int& nLiczba)
- {
- return std::to_string(nLiczba).length();
- }
- int removeDigit(int& nIndeks, int& nLiczba)
- {
- std::string sTemp = std::to_string(nLiczba);
- sTemp.erase(nIndeks-1, 1);
- return std::stoi(sTemp);
- }
- int checkNumber(int& nLiczba, int (*pfnGetDigit)(int&, int&), int (*pfnGetNumOfDigits)(int&), int (*pfnRemoveDigit)(int&, int&))
- {
- int nMianownik;
- double nUlamek, nTemp;
- for (unsigned i = 2; i <=100; i++)
- {
- nMianownik = nLiczba*i;
- for (int j = 1; j<=pfnGetNumOfDigits(nLiczba); j++)
- {
- for (int k = 1; k<=pfnGetNumOfDigits(nMianownik); k++)
- {
- if (pfnGetDigit(j, nLiczba) == pfnGetDigit(k, nMianownik))
- {
- if (pfnRemoveDigit(k, nMianownik)!=0)
- {
- nUlamek = (double)nLiczba/nMianownik;
- nTemp = (double)pfnRemoveDigit(j, nLiczba)/pfnRemoveDigit(k, nMianownik);
- if (nUlamek == nTemp)
- {;
- return i;
- }
- }
- }
- }
- }
- }
- return 0;
- }
- int main()
- {
- std::fstream plik("Liczby.txt", std::ios::out);
- int nWynik = 0;
- if (plik.is_open())
- {
- for (int i = 10; i <= 69000; i++)
- {
- nWynik = checkNumber(i, getDigit, getNumOfDigits, removeDigit);
- if (nWynik != 0)
- {
- if (i%10 != 0 && (nWynik*i)%10 != 0)
- {
- std::cout<<i<< "/" << i*nWynik<<" - " << nWynik*i<<"/"<<i<<std::endl;
- plik << i << "/" << i*nWynik<<" - " << nWynik*i<<"/"<<i<<std::endl;
- }
- }
- }
- }
- else std::cout<<"Nie mozna otworzyc pliku (Liczby.txt)"<<std::endl;
- plik.close();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement