您的位置:首页 > 其它

Codeforces刷题之路——58A Chat room

2016-08-24 14:26 155 查看
A. Chat room

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s.
It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the
word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it
will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.

Input

The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is
no less that 1 and no more than 100 letters.

Output

If Vasya managed to say hello, print "YES", otherwise print "NO".

Examples

input
ahhellllloou


output
YES


input
hlelo


output
NO


题目大意:输入的字符串中若存在有序“hello”即输出YES,否则NO。该"hello"不需要一定连续。
解题思路:使用字符数组{'h','e','l','l','o'},进行字符串扫描,若匹配成功,则对应的flag[i]=true,下次循环head=++j,并且跳出内层循环。只有当五个flag[i]均为true时才满足YES,否则NO。
注意事项:无

以下为解题代码(java实现)
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
char[] str = string.toCharArray();
char[] ch = {'h','e','l','l','o'};
boolean[]  flag = {false,false,false,false,false};
int head = 0;
for(int i = 0; i < ch.length;i++){
for(int j = head;j < string.length();j++){
if(ch[i] == str[j]){
flag[i] = true;
head = ++j;
break;
}
}
}
if(flag[0] && flag[1] &&flag[2] && flag[3] && flag[4]){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: