Created
December 1, 2017 03:52
-
-
Save jesuscmadrigal/be711c5b5d088d3021f84bd59bf16c06 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 str1= bigIntegerToString(n); | |
string str2=str1; | |
reverse(str2.begin(), str2.end()); | |
return (str2==str1); | |
} | |
BigInteger apply196(BigInteger n){ | |
string str1= bigIntegerToString(n); | |
string str2=str1; | |
reverse(str1.begin(), str1.end()); | |
return n+ stringToBigInteger(str1); | |
} | |
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