Files
exercises/dsa/ch4_string/dsa_0403_within_string.cpp
2026-10-16 10:21:53 +08:00

21 lines
493 B
C++

#include <iostream>
bool is_within(const std::string& str, const std::string& substr) {
int i = 0, j = 0;
for (; i < str.size() && j < substr.size(); i++) {
if (str[i] == substr[j]) { j++; }
}
return j == substr.size();
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string substr, str;
while (std::cin >> substr >> str) {
std::cout << (is_within(str, substr) ? "Yes" : "No") << std::endl;
}
return 0;
}