劝退
  • 板块学术版
  • 楼主bloodstalk
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/3/17 21:23
  • 上次更新2023/10/28 06:21:46
查看原帖
劝退
231543
bloodstalk楼主2022/3/17 21:23
#include<bits/stdc++.h>
using namespace std;

string s;
string a,b;
int l,l1,l2;
int weizhi;

void find(string s,string a)
{
	int sum=0,first;
	l=s.length();
	l1=a.length();
	b=a;
	b[0]=' ';
	s[l]=' ';
	while(s.find(a,weizhi)!=-1)/*如果s里面还有a子串*/
	{
		if(s.find(a,weizhi)==0)
		{
			if(s[s.find(a,weizhi)+l1]==' ') sum++;
		}
		else if(s.find(a,weizhi)+l1==l)
		{
			if(s[s.find(a,weizhi)-1]==' ') sum++;
		}
		else if(s[s.find(a,weizhi)-1]==' '&&s[s.find(a,weizhi)+l1]==' ') sum++;
		if(sum==1) first=s.find(a,weizhi);
		weizhi=s.find(a,weizhi);/*更新位置*/
		s.erase(weizhi,l1);/*从weizhi这一位置开始往后删去l1个字符,l1就是a的长度*/
		s.insert(weizhi,b);/*s.insert(weizhi,b);*/ /*再从weizhi这个地方插入b这个字符串*/
	}
	if(sum==0) cout<<"-1";
	else cout<<sum<<" "<<first;
}

int main()
{
	getline(cin,a);
	getline(cin,s);
	l=s.length();
	l1=a.length();
	for(int i=0;i<l;i++)
		if(s[i]>='A'&&s[i]<='Z') s[i]+=32;
	for(int i=0;i<l1;i++)
		if(a[i]>='A'&&a[i]<='Z') a[i]+=32;
	find(s,a);/*返回的是s所以直接输出*/
}
我要死了,WA了两个点,咋改都改不对
2022/3/17 21:23
加载中...