A - Chat room CodeForces - 58A

    xiaoxiao2022-07-06  217

    羞耻的写下这个 毕竟查找子序列 咱不擅长嘛= = 学到了就好 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

    #include<stdio.h> #include<string.h> int main() { char a[1001]; while(gets(a)) { int flag=0; int i; for(i=0; i<strlen(a); i++) { if(flag==0&&a[i]=='h') flag=1; else if(flag==1&&a[i]=='e')//这样做确实好,也保证了顺序性 flag=2; else if(flag==2&&a[i]=='l') flag=3; else if(flag==3&&a[i]=='l') flag=4; else if(flag==4&&a[i]=='o') flag=5; } if(flag==5) printf("YES\n"); else printf("NO\n"); } return 0; }
    最新回复(0)