20pts求调
查看原帖
20pts求调
747009
Spir1t楼主2024/2/28 20:20
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull = unsigned long long;
const ll INF=9223372036854775807;
const int inf=2147483647;
signed main() {
	//	freopen("123.in","r",stdin);
	//	freopen("123.out","w,",stdout);
	string s1, s2;
	getline(cin, s1);
	getline(cin, s2);
	int cnt = 0;
	int pos= -1;
	bool f = false;
	// 转换为小写方便匹配
	for (char& c : s1) {
		c = tolower(c);
	}
	size_t p = s2.find(s1, 0);
	while (p != string::npos) {
		if ((p == 0 || !isalpha(s2[p - 1])) && (p + s1.size() == s2.size() || !isalpha(s2[p + s1.size()]))) {
			cnt++;
			if (!f) {
				f = true;
				pos = p;
			}
		}
		p = s2.find(s1, p + 1);
	}
	if (cnt > 0) {
		cout << cnt << " " << pos << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}




2024/2/28 20:20
加载中...