水题一道,不涉及什么算法,注意s串和t串的输入顺序就好,搞清楚是在t串中去找s串,而不是在s串中去找t串,所以接下来的工作,就是用一个for循环来依次做最为朴素的匹配就好,如果ans==s串的长度,那么就说明匹配了.注意细节,稳稳出题。
# include<cstdio> # include<iostream> # include<cstring> using namespace std; # define MAX 100000 char s[MAX+10]; char t[MAX+10]; int main(void) { while ( scanf("%s%s",s,t)!=EOF ) { //scanf("%s",t); int n1 = strlen(s); int n2 = strlen(t); int ans = 0; for ( int i = 0, j = 0;i < n1&&j < n2; ) { if ( s[i] == t[j] ) { i++; j++; } else j++; ans = i; } if ( ans == n1 ) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }