Codeforces Problem-58A Chat Room
基本思想:
设置一个字符串a(或字符数组),利用while循环,依次读取输入的字符,如果输入的字符x=a[i],则i++,继续比较下一个,直到输入的字符为’\n’结束。最后判断i的值与hello的字符串长度值(5)进行比较,如果等于5,则输出YES,否则输出NO。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a="hello";
char x;
int i=0;
while (scanf("%c",&x)&&x!='\n')
{
if (x==a[i])
i++;
}
cout<<(i==5?"YES":"NO")<<endl;
return 0;
}