Damm algorithm: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add MACRO-11) |
m (→{{header|C++}}: Shortened code a bit) |
||
Line 760: | Line 760: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|C#|C sharp}} |
{{trans|C#|C sharp}} |
||
<syntaxhighlight lang="cpp">#include < |
<syntaxhighlight lang="cpp">#include <string> |
||
#include <cstdio> |
|||
⚫ | |||
⚫ | |||
{0, 3, 1, 7, 5, 9, 8, 6, 4, 2}, |
{0, 3, 1, 7, 5, 9, 8, 6, 4, 2}, |
||
{7, 0, 9, 2, 1, 5, 4, 8, 6, 3}, |
{7, 0, 9, 2, 1, 5, 4, 8, 6, 3}, |
||
Line 775: | Line 777: | ||
}; |
}; |
||
[[nodiscard]] bool damm(std::string s) noexcept { |
|||
bool damm(string s) { |
|||
int interim = 0; |
int interim = 0; |
||
for ( |
for (const auto c : s) { |
||
interim = TABLE[interim][c - '0']; |
interim = TABLE[interim][c - '0']; |
||
} |
} |
||
Line 785: | Line 786: | ||
int main() { |
int main() { |
||
auto |
for (const auto num : { 5724, 5727, 112946, 112949 }) { |
||
if (damm(std::to_string(num))) { |
|||
for (int num : numbers) { |
|||
⚫ | |||
using std::stringstream; |
|||
⚫ | |||
stringstream ss; |
|||
⚫ | |||
ss << num; |
|||
bool isValid = damm(ss.str()); |
|||
if (isValid) { |
|||
⚫ | |||
} else { |
|||
⚫ | |||
⚫ | |||
} |
} |
||
return 0; |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |