Created
November 23, 2017 01:11
-
-
Save victorcmadrigal/9fc7abfed0866e731b5a5850cafcb3ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
#include "BigIntegerLibrary.hh" | |
bool is_palindrome(BigInteger n){ | |
string a1= bigIntegerToString(n); | |
string a2=a1; | |
reverse(a2.begin(), a2.end()); | |
return (a2==a1); | |
} | |
BigInteger apply196(BigInteger n){ | |
string a1= bigIntegerToString(n); | |
string a2=a1; | |
reverse(a1.begin(), a1.end()); | |
return n+ stringToBigInteger(a1); | |
return n; | |
} | |
int main() { | |
int nolychrel=0, palin=0, lychrel=0; | |
BigInteger num; | |
int inferior, mayor; | |
cout <<"Calculadora de palíndromos"<<endl<<'\n'; | |
cout<<"Ingresa tu número inferior"<<endl; | |
cin>>inferior; | |
cout<<'\n'<<"Ingresa tu número mayor"<< endl; | |
cin>>mayor; | |
for(int i=inferior; i<=mayor; i++){ | |
num=i; | |
if(is_palindrome (num)==true){ | |
palin=palin+1; | |
} | |
else { | |
int contador=0; | |
bool lych= true; | |
while (contador<=30){ | |
num= (apply196(num)); | |
if((is_palindrome(num))==true){ | |
nolychrel=nolychrel+1; | |
lych=false; | |
break; | |
} | |
else{ | |
contador=contador+1; | |
} | |
} | |
if (lych){ | |
cout<<'\n'<<"Acabo de encontrar un número lychrel y es: "<< i<<endl; | |
lychrel=lychrel+1; | |
} | |
} | |
} | |
cout<<'\n'<<"Entre su rango de números hay:"<<endl<<'\n';; | |
cout<<palin<<" palíndromos"<<endl<<'\n';; | |
cout<<lychrel<<" números lychrel"<<endl<<'\n';; | |
cout<<nolychrel<<" números no lychrel"<<endl<<'\n';; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment