58A題目網址
題目解析
1.輸入字符串,問如果刪去其中的一些自發,能否得到hello,如果能就輸出YES,否則輸出NO
舉例:
輸入:
ahhellllloou
輸出:
YES
2.注意點:
因為C語言沒有java中的匹配字符串,則新建立一個 word[6]=“hello”;
在循環中使用word去與s匹配,當匹配到了就
count++;
j++;
當count==5輸出YES,否則輸出NO
代碼
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{char s[100]={'\0'};char word[6]="hello";int count=0,j=0;scanf("%s",s);for(int i=0;i<strlen(s);i++){if(word[j]==s[i]){count++;j++;}}if(count==5)printf("YES");else{printf("NO");}getchar();//接收回車符getchar();//這才是讓控制臺停住return 0;
}