diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-24 22:54:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-24 22:54:35 +0100 |
| commit | fdee069d634b2d991a623c6d6b05fa2389d0fc67 (patch) | |
| tree | ed3a8dad98b1e84239ec76c2f6ff70f933f8735a /challenge-009/paulo-custodio/cpp/ch-1.cpp | |
| parent | c9d2138108edc544718e2fe95dc643f027cd62d4 (diff) | |
| parent | ea269468630076e333ed440d17f4c8679d3d4e9a (diff) | |
| download | perlweeklychallenge-club-fdee069d634b2d991a623c6d6b05fa2389d0fc67.tar.gz perlweeklychallenge-club-fdee069d634b2d991a623c6d6b05fa2389d0fc67.tar.bz2 perlweeklychallenge-club-fdee069d634b2d991a623c6d6b05fa2389d0fc67.zip | |
Merge pull request #4338 from pauloscustodio/paulo-custodio
Add C and C++ solutions to challenge 009
Diffstat (limited to 'challenge-009/paulo-custodio/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-009/paulo-custodio/cpp/ch-1.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-009/paulo-custodio/cpp/ch-1.cpp b/challenge-009/paulo-custodio/cpp/ch-1.cpp new file mode 100644 index 0000000000..a647b3cfd7 --- /dev/null +++ b/challenge-009/paulo-custodio/cpp/ch-1.cpp @@ -0,0 +1,37 @@ +/* +Challenge 009 + +Challenge #1 +Write a script that finds the first square number that has at least 5 distinct +digits.This was proposed by Laurent Rosenfeld. +*/ + +#include <iostream> +using namespace std; + +int num_diff_digits(int n) { + bool digits[10] = {0}; + int count = 0; + while (n > 0) { + int digit = n % 10; + n /= 10; + if (!digits[digit]) { + digits[digit] = true; + count++; + } + } + return count; +} + +int main(int argc, char* argv[]) { + int num = 0; + if (argc == 2) + num = atoi(argv[1]); + if (num == 0) + num = 5; + + int n = 1; + while (num_diff_digits(n * n) < num) + n++; + cout << n * n << endl; +} |
