ADDED .clang-format Index: .clang-format ================================================================== --- /dev/null +++ .clang-format @@ -0,0 +1,60 @@ +--- +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +AlignEscapedNewlines: Left +AlignOperands: 'true' +AlignTrailingComments: 'true' +AllowAllParametersOfDeclarationOnNextLine: 'true' +AllowShortBlocksOnASingleLine: 'false' +AllowShortCaseLabelsOnASingleLine: 'false' +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: 'false' +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: 'false' +AlwaysBreakTemplateDeclarations: 'Yes' +BinPackArguments: 'false' +BinPackParameters: 'false' +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: 'true' +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakStringLiterals: 'true' +CompactNamespaces: 'false' +ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' +Cpp11BracedListStyle: 'true' +DerivePointerAlignment: 'false' +DisableFormat: 'false' +FixNamespaceComments: 'true' +IncludeBlocks: Preserve +IndentCaseLabels: 'false' +IndentPPDirectives: AfterHash +IndentWrappedFunctionNames: 'false' +JavaScriptQuotes: Single +JavaScriptWrapImports: 'true' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +NamespaceIndentation: Inner +PointerAlignment: Right +ReflowComments: 'true' +SortIncludes: 'true' +SortUsingDeclarations: 'true' +SpaceAfterCStyleCast: 'true' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeCpp11BracedList: 'true' +SpaceBeforeCtorInitializerColon: 'false' +SpaceBeforeInheritanceColon: 'false' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'true' +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInContainerLiterals: 'false' +SpacesInParentheses: 'false' +SpacesInSquareBrackets: 'false' +Standard: Auto +UseTab: Never + +... Index: src/main.cxx ================================================================== --- src/main.cxx +++ src/main.cxx @@ -1,89 +1,92 @@ -#include +#include #include +#include #include -#include // Неободимо для поддержки Unicode #ifdef _WIN32 -#include // SetConsoleOutputCP +# include // SetConsoleOutputCP #else -#include +# include #endif using std::cin, std::cout, std::endl, std::flush, std::setw; using std::stack, std::tuple; -void f_rec(const size_t fun_count, const size_t max_recursion_depth, const size_t n = 1, const size_t depth = 0) -{ - cout << setw(depth) << "" << n << endl; - - if (depth >= max_recursion_depth) - return; - - for (size_t i = 0; i < fun_count - 1; i++) - { - f_rec(fun_count, max_recursion_depth, (n + i) % fun_count + 1, depth + 1); - } +void f_rec( + const size_t fun_count, + const size_t max_recursion_depth, + const size_t n = 1, + const size_t depth = 0) +{ + cout << setw(depth) << "" << n << endl; + + if (depth >= max_recursion_depth) + return; + + for (size_t i = 0; i < fun_count - 1; i++) + { + f_rec(fun_count, max_recursion_depth, (n + i) % fun_count + 1, depth + 1); + } } void f_iter(const size_t fun_count, const size_t max_recursion_depth) { - using stack_item = tuple; - - stack return_stack; - return_stack.push({1, 0}); - - while (!return_stack.empty()) - { - auto [n, depth] = return_stack.top(); - return_stack.pop(); - - stack queue; - - // BEGIN unmodified code - cout << setw(depth) << "" << n << endl; - - if (depth >= max_recursion_depth) - continue; - - for (size_t i = 0; i < fun_count - 1; i++) - { - queue.push({(n + i) % fun_count + 1, depth + 1}); - } - // END unmodified code - - while (!queue.empty()) - { - return_stack.push(queue.top()); - queue.pop(); - } - } + using stack_item = tuple; + + stack return_stack; + return_stack.push({1, 0}); + + while (!return_stack.empty()) + { + auto [n, depth] = return_stack.top(); + return_stack.pop(); + + stack queue; + + // BEGIN unmodified code + cout << setw(depth) << "" << n << endl; + + if (depth >= max_recursion_depth) + continue; + + for (size_t i = 0; i < fun_count - 1; i++) + { + queue.push({(n + i) % fun_count + 1, depth + 1}); + } + // END unmodified code + + while (!queue.empty()) + { + return_stack.push(queue.top()); + queue.pop(); + } + } } int main() { - - // Включаем поддержку Unicode + // Включаем поддержку Unicode #ifdef _WIN32 - SetConsoleOutputCP(65001); + SetConsoleOutputCP(65001); #else - std::locale::global(std::locale("")); + std::locale::global(std::locale("")); #endif - size_t fun_count; - size_t max_recursion_depth; - - cout << u8"Кол-во функций: " << flush; - cin >> fun_count; - - cout << u8"Макс. глубина рекурсии: " << flush; - cin >> max_recursion_depth; - - cout << u8"Вывод рекурсивной функции:" << endl; - f_rec(fun_count, max_recursion_depth); - - cout << u8"Вывод нерекурсивной функции:" << endl; - f_iter(fun_count, max_recursion_depth); - - return 0; + size_t fun_count; + size_t max_recursion_depth; + + cout << u8"Кол-во функций: " << flush; + cin >> fun_count; + + cout << u8"Макс. глубина рекурсии: " << flush; + cin >> max_recursion_depth; + + cout << u8"Вывод рекурсивной функции:" << endl; + f_rec(fun_count, max_recursion_depth); + + cout << u8"Вывод нерекурсивной функции:" << endl; + f_iter(fun_count, max_recursion_depth); + + return 0; }