-
Notifications
You must be signed in to change notification settings - Fork 3
Трясцин Савелий Валерьевич #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #include <cstring> | ||
|
|
||
| void hide_secret(char* const text, const char* const secret) | ||
| { | ||
| if (text == nullptr || secret == nullptr) | ||
| return; | ||
| int secretLength = strlen(secret); | ||
| if ( secretLength == 0) | ||
| return; | ||
| for (int i = 0; text[i] != '\0'; i++) | ||
| { | ||
| bool matched = true; | ||
| bool needEnd = false; | ||
| for (int j = i; j - i < secretLength; j++) | ||
| { | ||
| if (text[j] == '\0') | ||
| { | ||
| needEnd = true; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если заранее проверить длину |
||
| } | ||
| if (text[j] != secret[j - i]) | ||
| { | ||
| matched = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!matched) | ||
| { | ||
| continue; | ||
| } | ||
| if (needEnd) | ||
| { | ||
| break; | ||
| } | ||
| text[i] = '\x01'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вам, пожалуй, стоит перед работой функции посмотреть, нет ли в ней
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно так же попробовать организовать поиск неиспользуемого символа вместо |
||
| } | ||
|
|
||
| int lastStart = -1; | ||
| for (int i = 0; text[i] != '\0'; i++) | ||
| { | ||
| if (text[i] == '\x01') | ||
| { | ||
| lastStart = i; | ||
| } | ||
|
|
||
| if (lastStart == -1) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if (i - lastStart < secretLength) | ||
| { | ||
| text[i] = 'x'; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Длину
textтоже можно заранее проверить