Skip to content

Commit

Permalink
Merge pull request #74 from FrankKair/cpp-004
Browse files Browse the repository at this point in the history
Feat: Adds C++ 004
  • Loading branch information
FrankKair committed May 29, 2018
2 parents 5a32412 + 3f16384 commit fc2d718
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/004/p004.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;

int reverse(int n) {
int v = n, rv = 0;
do {
rv = (rv*10) + (v%10);
v = v/10;
} while (v > 0);
return rv;
}

int solve() {
int v = 0;
for (int i = 999; i > 99; i--) {
for (int j = 999; j > i-100; j--) {
v = i * j;
if (v == reverse(v)) {
return v;
}
}
}
return 0;
}

int main() {
int result = solve();
cout << result << endl;
}

0 comments on commit fc2d718

Please sign in to comment.