题目
out
3
abaabbabaabb ab
abc abc
ababababababa aba
思路
善用string库里面的subtr和operator==
(用char比较也可以,就是函数得自己写罢了)
substr(pos,n)
pos表示位置,n表示截取的长度,pos后续不够n那就只截取不足的部分
if(s.substr(pos,n) == short)
pos += short - 1;
else
cout << longn[pos];
代码
#include<iostream>
using namespace std;
int main()
{
int n; cin >> n;
for(int i = 0; i < n; i++)
{
cout << "case #" << i << ":" << endl;
string lon, sho;
cin >> lon >> sho;
int l = lon.length();
int sl = sho.length();
for(int i = 0; i < l; i++)
{
string t = lon.substr(i , sl);
if(t == sho)
i += sl - 1;
else
cout << lon.at(i);
}
cout << endl;
}
}