Codeforces Beta Round #54 (Div. 2) A. Chat room

http://codeforces.com/problemset/problem/58/A

题意:
如果一个字符串可从左往右一次提取出hello,则输出YES,否则NO。
满足要求的字符串是由hello在任意位置插入任意个字符。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;

int main() {
string hi = "hello", s;
cin >> s;
int i = 0, j = 0;
while (i < s.length() && j < 5) {
if (s[i] == hi[j]) {
j++;
}
i++;
}
if (j == 5) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
};