现在的位置: 首页 > 综合 > 正文

A. Chat room

2013年03月02日 ⁄ 综合 ⁄ 共 1552字 ⁄ 字号 评论关闭
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".

Sample test(s)
input
ahhellllloou
output
YES
input
hlelo
output
NO

解题说明:这道题就是判断一个字符串中是否存在hello这个字符,而且是顺序的。为了节省时间,最好一遍遍历完成,可以先找到h,然后在剩下的字符中找到e,依次再找l l o即可,这样也能保证顺序。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
	int i;
	int flag;
	int temp1,temp2,temp3,temp4,temp5;
	char a[105];
	temp1=0;
	temp2=0;
	temp3=0;
	temp4=0;
	temp5=0;
	scanf("%s",&a);
	for(i=0;a[i]!='\0';i++)
	{
		if(a[i]=='h')
		{
			flag=i+1;
			temp1=1;
			break;
		}
	}
	for(i=flag;a[i]!='\0';i++)
	{
		if(a[i]=='e')
		{
			flag=i+1;
			temp2=1;
			break;
		}
	}
	for(i=flag;a[i]!='\0';i++)
	{
		if(a[i]=='l')
		{
			flag=i+1;
			temp3=1;
			break;
		}
	}
	for(i=flag;a[i]!='\0';i++)
	{
		if(a[i]=='l')
		{
			flag=i+1;
			temp4=1;
			break;
		}
	}
	for(i=flag;a[i]!='\0';i++)
	{
		if(a[i]=='o')
		{
			flag=i+1;
			temp5=1;
			break;
		}
	}

	if(temp1==1&&temp2==1&&temp3==1&&temp4==1&&temp5==1)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
    return 0;
}

抱歉!评论已关闭.