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
output
input
output
题目大意:输入的字符串中若存在有序“hello”即输出YES,否则NO。该"hello"不需要一定连续。
解题思路:使用字符数组{'h','e','l','l','o'},进行字符串扫描,若匹配成功,则对应的flag[i]=true,下次循环head=++j,并且跳出内层循环。只有当五个flag[i]均为true时才满足YES,否则NO。
注意事项:无
以下为解题代码(java实现)
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"); } } }
相关文章推荐
- Codeforces刷题之路——266A Stones on the Table
- Codeforces刷题之路——263A Beautiful Matrix
- 开始codeforces的奋斗之路
- Codeforces刷题之路——110A Nearly Lucky Number
- Codeforces刷题之路——467A George and Accommodation
- Codeforces刷题之路——339A Helpful Maths
- Codeforces刷题之路——148A Insomnia cure
- Codeforces刷题之路——236A Boy or Girl
- Codeforces刷题之路——112A Petya and Strings
- Codeforces刷题之路——711A Bus to Udayland
- Codeforces刷题之路——281A Word Capitalization
- Codeforces刷题之路——546A Soldier and Bananas
- 算法之路四:codeforces 4A
- Codeforces刷题之路——133A HQ9+
- Codeforces刷题之路——131A cAPS lOCK
- Codeforces刷题之路——710A King Moves
- Codeforces刷题之路——41A Translation
- Codeforces刷题之路——116A Tram
- Java学习之路:不走弯路,就是捷径(转载)
- 教为学:Oracle 11g OCP之路(三):网络配置详解