Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d07caf7

Browse files
author
werewolf
committed
finish regex part
1 parent 807615d commit d07caf7

File tree

3 files changed

+18
-36
lines changed

3 files changed

+18
-36
lines changed

‎src/algorithm/DNA_Analyzer.cc‎

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -143,50 +143,34 @@ void DNA_Analyzer::RegexAlgorithm(const std::filesystem::path& path) {
143143
std::string seq, pattern;
144144
file >> seq >> pattern;
145145

146-
std::size_t n = seq.size();
147-
std::size_t m = pattern.size();
146+
conststd::size_t n = seq.size();
147+
conststd::size_t m = pattern.size();
148148

149149
std::vector<std::vector<bool>> dp(n + 1, std::vector<bool>(m + 1, false));
150150
dp[0][0] = true;
151151

152-
// Обработка случая пустой строки
153-
for (std::size_t j = 2; j <= m; j++) {
154-
if (pattern[j - 1] == '*' && dp[0][j - 2]) {
155-
dp[0][j] = true;
156-
}
157-
}
158-
159-
// Заполнение таблицы по переходам для i >= 1 и j >= 1
160-
for (std::size_t i = 1; i <= n; i++) {
161-
for (std::size_t j = 1; j <= m; j++) {
162-
if (symbol(seq[i - 1]) == symbol(pattern[j - 1]) || pattern[j - 1] == '.') {
163-
// Первый тип перехода
164-
dp[i][j] = dp[i - 1][j - 1];
165-
} else if (pattern[j - 1] == '?') {
166-
// Второй тип перехода
167-
dp[i][j] = dp[i - 1][j - 1] || dp[i][j - 1];
168-
} else if (pattern[j - 1] == '*') {
169-
// Третий тип перехода
170-
if (dp[i][j - 2]) {
171-
dp[i][j] = true;
172-
} else if (symbol(seq[i - 1]) == symbol(pattern[j - 2]) || pattern[j - 2] == '.') {
173-
dp[i][j] = dp[i - 1][j];
174-
}
175-
} else if (pattern[j - 1] == '+') {
176-
// Четвертый тип перехода
177-
dp[i][j] = dp[i - 1][j] && (symbol(seq[i - 1]) == symbol(pattern[j - 2]) || pattern[j - 2] == '.');
152+
for (auto i = seq.begin(); i != seq.end(); ++i) {
153+
const auto x = std::distance(seq.begin(), i) + 1;
154+
for (auto j = pattern.begin(); j != pattern.end(); ++j) {
155+
const auto y = std::distance(pattern.begin(), j) + 1;
156+
157+
if (symbol(*i) == symbol(*j) || *j == '.') {
158+
dp[x][y] = dp[x - 1][y - 1];
159+
} else if (*j == '?') {
160+
dp[x][y] = dp[x - 1][y - 1] || dp[x][y - 1];
161+
} else if (*j == '*') {
162+
dp[x][y] = dp[x - 1][y - 1] || dp[x - 1][y];
163+
} else if (*j == '+') {
164+
dp[x][y] = (dp[x][y - 1] || dp[x - 1][y]) && (symbol(*i) == symbol(*(j - 1)) || *(j - 1) == '.');
178165
}
179166
}
180167
}
181168

182-
std::cout << dp[n][m] << std::endl;
169+
std::cout << (dp[n][m] ? "True" : "False") << std::endl;
183170
}
184171

185172
char DNA_Analyzer::symbol(char c) {
186-
if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
187-
return c;
188-
}
189-
return '0円';
173+
return std::find(m_ABC.begin(), m_ABC.end(), c) != m_ABC.end() ? c : '0円';
190174
}
191175

192176
void DNA_Analyzer::KSimilarAlgorithm(const std::filesystem::path& path) {

‎src/algorithm/DNA_Analyzer.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DNA_Analyzer {
3434
const std::size_t m_rk_mod = 1e9 + 9;
3535
const std::size_t m_rk_base = 31;
3636

37-
std::array<int, 256> m_weights = {};
37+
std::array<int, 256> m_weights = {'0円'};
3838

3939
std::string ReadFile(const std::filesystem::path& path);
4040
void CalculateMassHash(const std::string &src, std::vector<std::size_t> &hash, const std::size_t size, const std::vector<std::size_t> &exp);

‎test_3.txt‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /