#include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; // Разворот C-строки int main1() { ios::sync_with_stdio(false); cin.tie(nullptr); // Готовим C-шную строку. char* s = new char[1000]; int i = 0; for (char c = 0; c = char(getchar()), c != '\n'; ++i) { s[i] = c; } s[i] = '\0'; // Развернем строку. std::reverse(s, s + i); cout << s; delete[] s; return 0; } // Разворот строки std::string int main2() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; // Развернем строку. std::reverse(s.begin(), s.end()); cout << s; return 0; } // Генерация палиндрома int main4() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; cout << s; reverse(s.begin(), s.end()); cout << s; return 0; } // Сложение всех чисел, входящих в строку. int main5() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; // Можно добавить символ, чтобы не добавлять current_num после основного цикла. // s.append(1, '*'); // 2j3 // a3874dj33de4 int current_num = 0; int result = 0; for (char c : s) { if (c >= '0' && c <= '9') { current_num = current_num * 10 + (c - '0'); } else { result += current_num; current_num = 0; } } result += current_num; cout << result; return 0; } // Префикс-функция int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; vector pi(s.size()); int j = 0; for (size_t i = 1; i < s.size(); i++) { while (j > 0 && s[j] != s[i]) j = pi[j - 1]; if (s[j] == s[i]) pi[i] = ++j; // else оставляем pi[i] равным 0 } for (int i : pi) cout << i << " "; return 0; }