Project Euler #4 - Finding the largest palindrome that is the product of two three-digit numbers.
up vote
0
down vote
favorite
This is my attempt at the 4th problem on Project Euler:
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int palindromeCheck(int pp) {
int temp = pp;
string palindrome = std::to_string(pp);
auto it1 = palindrome.begin();
auto it2 = palindrome.end() - 1;
while (it2 - it1 >= 1) {
if (*it1 == *it2) {
++it1;
--it2;
}
else {
return 0;
}
}
return 1;
}
int main()
{
int highestPalindrome = 0;
for (int x = 100; x <= 999; x++) {
for (int y = 100; y <= 999; y++) {
int newDigit = x * y;
int paliCheck = palindromeCheck(newDigit);
if (paliCheck == 1) {
if (newDigit > highestPalindrome) {
highestPalindrome = newDigit;
}
}
}
}
std::cout << highestPalindrome;
}
I'm trying to get better at both C++ and problem-solving so any help/tips are appreciated.
c++ programming-challenge
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
This is my attempt at the 4th problem on Project Euler:
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int palindromeCheck(int pp) {
int temp = pp;
string palindrome = std::to_string(pp);
auto it1 = palindrome.begin();
auto it2 = palindrome.end() - 1;
while (it2 - it1 >= 1) {
if (*it1 == *it2) {
++it1;
--it2;
}
else {
return 0;
}
}
return 1;
}
int main()
{
int highestPalindrome = 0;
for (int x = 100; x <= 999; x++) {
for (int y = 100; y <= 999; y++) {
int newDigit = x * y;
int paliCheck = palindromeCheck(newDigit);
if (paliCheck == 1) {
if (newDigit > highestPalindrome) {
highestPalindrome = newDigit;
}
}
}
}
std::cout << highestPalindrome;
}
I'm trying to get better at both C++ and problem-solving so any help/tips are appreciated.
c++ programming-challenge
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my attempt at the 4th problem on Project Euler:
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int palindromeCheck(int pp) {
int temp = pp;
string palindrome = std::to_string(pp);
auto it1 = palindrome.begin();
auto it2 = palindrome.end() - 1;
while (it2 - it1 >= 1) {
if (*it1 == *it2) {
++it1;
--it2;
}
else {
return 0;
}
}
return 1;
}
int main()
{
int highestPalindrome = 0;
for (int x = 100; x <= 999; x++) {
for (int y = 100; y <= 999; y++) {
int newDigit = x * y;
int paliCheck = palindromeCheck(newDigit);
if (paliCheck == 1) {
if (newDigit > highestPalindrome) {
highestPalindrome = newDigit;
}
}
}
}
std::cout << highestPalindrome;
}
I'm trying to get better at both C++ and problem-solving so any help/tips are appreciated.
c++ programming-challenge
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This is my attempt at the 4th problem on Project Euler:
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int palindromeCheck(int pp) {
int temp = pp;
string palindrome = std::to_string(pp);
auto it1 = palindrome.begin();
auto it2 = palindrome.end() - 1;
while (it2 - it1 >= 1) {
if (*it1 == *it2) {
++it1;
--it2;
}
else {
return 0;
}
}
return 1;
}
int main()
{
int highestPalindrome = 0;
for (int x = 100; x <= 999; x++) {
for (int y = 100; y <= 999; y++) {
int newDigit = x * y;
int paliCheck = palindromeCheck(newDigit);
if (paliCheck == 1) {
if (newDigit > highestPalindrome) {
highestPalindrome = newDigit;
}
}
}
}
std::cout << highestPalindrome;
}
I'm trying to get better at both C++ and problem-solving so any help/tips are appreciated.
c++ programming-challenge
c++ programming-challenge
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 8 mins ago
user2925800
1
1
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user2925800 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
user2925800 is a new contributor. Be nice, and check out our Code of Conduct.
user2925800 is a new contributor. Be nice, and check out our Code of Conduct.
user2925800 is a new contributor. Be nice, and check out our Code of Conduct.
user2925800 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208422%2fproject-euler-4-finding-the-largest-palindrome-that-is-the-product-of-two-thr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown