Kursova

Check-in [65e10b5e58]
Login

Check-in [65e10b5e58]

Overview
Comment:MVP
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 65e10b5e58497e8c7e30b309cc57eaaffec498507cd586bf3f0fe2df7214cfa9
User & Date: 4l1v3b33f on 2021-01-12 10:57:05
Other Links: manifest | tags
Context
2021-01-12
11:11
Fixed whitespace check-in: ede199dcd5 user: 4l1v3b33f tags: trunk
10:57
MVP check-in: 65e10b5e58 user: 4l1v3b33f tags: trunk
10:50
initial empty check-in check-in: 3e060c3242 user: 4l1v3b33f tags: trunk
Changes

Added .vscode/settings.json version [c2cfc305a9].






1
2
3
4
5
+
+
+
+
+
{
  "files.exclude": {
    "build": true
  }
}

Added CMakeLists.txt version [2225fcdfcd].







1
2
3
4
5
6
+
+
+
+
+
+
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

project(Kursova LANGUAGES CXX)

add_executable(main src/main)
target_compile_features(main PRIVATE cxx_std_17)

Added src/main.cxx version [5c9cbc0726].























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#include <iostream>
#include <iomanip>
#include <stack>
#include <array>

// Неободимо для поддержки Unicode
#ifdef _WIN32
#include <windows.h> // SetConsoleOutputCP
#else
#include <locale>
#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_iter(const size_t fun_count, const size_t max_recursion_depth)
{
	using stack_item = tuple<size_t, size_t>;

	stack<stack_item> return_stack;
	return_stack.push({1, 0});

	while (!return_stack.empty())
	{
		auto [n, depth] = return_stack.top();
		return_stack.pop();

		stack<stack_item> 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
#ifdef _WIN32
	SetConsoleOutputCP(65001);
#else
	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;
}