Four is magic: Difference between revisions
Content added Content deleted
m (C - minor change to comply with task requirements) |
m (C++ - changed code to comply with task requirements) |
||
Line 329: | Line 329: | ||
} |
} |
||
std::string magic(integer n) { |
|||
std::string result; |
|||
for (unsigned int i = 0; ; ++i) { |
for (unsigned int i = 0; ; ++i) { |
||
std::string text(cardinal(n)); |
std::string text(cardinal(n)); |
||
if (i == 0) |
if (i == 0) |
||
text[0] = uppercase(text[0]); |
text[0] = uppercase(text[0]); |
||
result += text; |
|||
if (n == 4) { |
if (n == 4) { |
||
result += " is magic."; |
|||
break; |
break; |
||
} |
} |
||
integer len = text.length(); |
integer len = text.length(); |
||
result += " is "; |
|||
result += cardinal(len); |
|||
result += ", "; |
|||
n = len; |
n = len; |
||
} |
} |
||
return result; |
|||
} |
|||
void test_magic(integer n) { |
|||
std::cout << magic(n) << '\n'; |
|||
} |
} |
||
int main() { |
int main() { |
||
test_magic(5); |
|||
test_magic(13); |
|||
test_magic(78); |
|||
test_magic(797); |
|||
test_magic(2739); |
|||
test_magic(4000); |
|||
test_magic(7893); |
|||
test_magic(93497412); |
|||
test_magic(2673497412U); |
|||
test_magic(10344658531277200972ULL); |
|||
return 0; |
return 0; |
||
}</lang> |
}</lang> |