Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
115781 | 彭士宝 | 如何得到"hello" | C++ | Accepted | 1 MS | 280 KB | 706 | 2025-04-04 16:53:50 |
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; // 读取输入字符串 string target = "hello"; int targetIndex = 0; // 目标字符串的指针 for (char c : s) { // 遍历输入字符串 if (c == target[targetIndex]) { // 如果当前字符匹配 targetIndex++; // 移动目标字符串的指针 if (targetIndex == target.size()) { // 如果目标字符串匹配完成 cout << "YES" << endl; return 0; // 提前结束程序 } } } cout << "NO" << endl; // 如果遍历完输入字符串仍未匹配完成 return 0; }