题意 :给出两个字符串s、t,问s是不是t的子串(不用连续)。
——>>一个个扫描……感觉这次写得挺。。。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s, t;
while(cin >> s >> t){
int len_s = s.length(), len_t = t.length(), i, j;
for(i = 0, j = 0; i < len_t; i++){
if(t[i] == s[j] && (++j) == len_s) break;
}
if(j == len_s) cout << "Yes" << endl;
else cout << "No" <<endl;
}
return 0;
}
本文介绍了一个简单的C++程序,用于解决UVA在线评测中的一道题目:判断一个字符串是否为另一个字符串的不连续子串。通过逐字符比对的方式实现了这一功能。
909

被折叠的 条评论
为什么被折叠?



