2 solutions
-
3
//两个字符串同时往后移动,如果第一个和第二个相同,则继续同时走,否则只有第二个字符串往后走 #include<bits/stdc++.h> using namespace std; const int N=100010; string s1,s2; int main() { while(cin>>s1>>s2) { int n=s1.size(); int m=s2.size(); int i=0,j=0,cnt=0; while(i<n&&j<m) //两个都没有走到尾 { if(s1[i]==s2[j]) //相同就同时往后走 { cnt++; i++; j++; } else //只有第二个往后走 { j++; } } if(cnt==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
-
0
#include<bits/stdc++.h> using namespace std; const int N=100010; string s1,s2; int main() { while(cin>>s1>>s2) { int n=s1.size(); int m=s2.size(); int i=0,j=0,cnt=0; while(i<n&&j<m) { if(s1[i]==s2[j]) { i++; j++; cnt++; } else { j++; } } if(cnt==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
- 1
Information
- ID
- 80
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- (None)
- # Submissions
- 44
- Accepted
- 20
- Uploaded By