Skip to content

Instantly share code, notes, and snippets.

@Jan200101
Created January 18, 2018 18:18
Show Gist options
  • Select an option

  • Save Jan200101/9954a45112e95f973da6c314c8d58a8e to your computer and use it in GitHub Desktop.

Select an option

Save Jan200101/9954a45112e95f973da6c314c8d58a8e to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int anfang = 1000000;
int ende = 1200000;
// int ende = 9999999;
int arrays[ende-anfang] = {};
for (int loop = anfang; loop <= ende; loop++)
{
string zahl = to_string(loop);
string zahlreversed = zahl;
reverse(zahlreversed.begin(), zahlreversed.end());
// If no 0 is found in the string continue
if (zahl.find("0") == string::npos)
{
for (int multiplikator = 0; multiplikator <= 10; multiplikator++)
{
// If any mulitple of the current number is the reverse of the number its a hit
if (to_string(multiplikator*loop) == zahlreversed)
{
// Safe the first half of the string in its own variable
string t = zahl.substr(0, zahl.length() / 2);
// reverse that variable
reverse(t.begin(), t.end());
// if the number ends with the reversed varible continue
if (equal(t.rbegin(), t.rend(), zahl.rbegin()))
{
arrays[loop-anfang] = loop;
}
}
}
}
}
for (int i = 0; i < (ende-anfang); i++)
{
if (arrays[i])
{
cout << arrays[i] << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment