Skip to content

Instantly share code, notes, and snippets.

@MarielCisneros
Created November 23, 2017 00:38
Show Gist options
  • Save MarielCisneros/5338120537e5371e63a0c9436a18971e to your computer and use it in GitHub Desktop.
Save MarielCisneros/5338120537e5371e63a0c9436a18971e to your computer and use it in GitHub Desktop.
#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'<<"Ingresa el rango a analizar:"<<endl<<'\n';;
cout<<palin<<"Los palíndromos son: "<<endl<<'\n';;
cout<<lychrel<<"Los números lychrel son: "<<endl<<'\n';;
cout<<nolychrel<<"Los números no lychrel son: "<<endl<<'\n';;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment