-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers.cpp
More file actions
148 lines (136 loc) · 4.43 KB
/
numbers.cpp
File metadata and controls
148 lines (136 loc) · 4.43 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main(){
setlocale(LC_ALL, "ru");
srand(time(0));
string str = "1";
int step;
bool ind = false;
int buff = 0;
//--------------------1 point-------------------------------
cout << "enter our degree(bytes): ";
cin >> step;
for (int i = 0; i < step; i++) {
//шагаем по всей строке
for (int j = str.size() - 1; j >= 0; j--) {
//cout << str[j] << endl;
//если от 0 до 4 - просто умножаем
if (str[j] <= 52) {
str[j] = (char)(((str[j] - 48) * 2) + 48);
if (ind) {
str[j]++;
ind = false;
}
//cout << "str:" << str[j] << endl;
}
//если нет - начинается игра на выживание :_) если 5 - отнимаем единицу
else {
str[j] = (char)(((str[j] - 48) * 2) % 10 + 48);
if (ind && buff - j == 1) {
str[j]++;
ind = false;
}
ind = true;
buff = j;
//cout << str[j] << endl;
}
if (ind && j == 0) {
str.insert(str.begin(), 48);
str[j]++;
ind = false;
}
}
}
cout << "max lim = " << str << endl;
//----------------------2 point-----------------------
string code = str;
int counter = 0;
//отдельный случай для первого элемента (генерим по самому старшему разряду, если имеется ошибка - откат и все заново)
for (int i = 0; i < str.size(); i++) {
if (i == 0) {
int buf = code[0];
code[i] = (((code[i] - 48) * (rand() % 1000)) % 10) + 48;
if (code[0] > buf) {
code[0] = buf;
}
}
else {
code[i] = (((code[i] - 48) * (rand() % 1000)) % 10) + 48;
}
}
//обеспечивает различную разрядность (7 раз чтоб обеспечить диапазон, пока все циферки не заменим на 0)
if (str.size() > 7) {
for (int i = 0; i < str.size() / 7; i++) {
for (int j = rand() % 7; j < 7; j++) {
code[counter] = 48;
counter++;
}
}
}
else {
for (int i = 0; i < str.size(); i++) {
if (rand() % 2 == 0) {
code[counter] = 48;
counter++;
}
}
}
//удаляем нули - уменьшаем разрядность
while (code[0] == 48)
{
if (code.size() == 1) {
break;
}
code.erase(code.begin());
}
cout << endl << "code = " << code;
//-------------------3 point-------------------
ind = false;
string decod = "0";
clock_t start;
start = clock();
long double t = 0;
int min = 0;
int hour = 0;
//перебор ключей + счетчик времени
while (true) {
//cout << decod << endl;
t = (clock() - start) / (double)CLOCKS_PER_SEC;
if (t > 60) {
min++;
t = 0;
}
if (min == 60) {
hour++;
min = 0;
}
if (decod == code) {
cout << "\n\nЖЕВАТЬ КАРТОН БЕЗ ХЛЕБА, НЕУЖЕЛИ ОНО ЗАКОНЧИЛОСЬ???????????" << endl;
break;
}
for (int j = decod.size() - 1; j >= 0; j--) {
//уменьшаем разрядность
if (j == 0 && decod[j] == 57) {
decod[j] = 48;
decod.insert(decod.begin(), 49);
break;
}
//возвращаем единицу, которую забрали
else {
decod[j] = ((decod[j] + 1) % 48 % 10) + 48;
if (decod[j] != 48) {
break;
}
}
}
}
cout << "\ndecode = " << decod << endl << "with time = "
<< hour << " hours "
<< min << " minutes "
<< fixed << setprecision(10) << t << " seconds " << endl;
system("pause");
}