to to to和to to都是错的
查看原帖
to to to和to to都是错的
1120932
ansan楼主2023/11/29 23:59
#include<stdio.h>
#include<cstring>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s, str;
	cin >> str;
	getchar();
	getline(cin, s);
	int i, j = 0, flag = 0, n, count = 0;
	for(i = 0; i < s.length(); i++){
		if(s[i] >= 'A' && s[i] <= 'Z')
		s[i] = tolower(s[i]);
	}
	for(i = 0; i < str.size(); i++){
		if(str[i] >= 'A' && str[i] <= 'Z')
		str[i] = tolower(str[i]);
	}
	str = " " + str + " ";
	s = " " + s + " ";
	for(i = 0; i < s.size(); i++){
		if(s[i] != str[j])
			j = 0;		
		else if(s[i] == str[j]){
			j++;
			if(j == str.size()){
				if(count == 0)
				flag = i - j + 1;
				j = 0;
				count++;
			}
		}
	}
	if(count == 0)
	cout << -1;
	else
	cout << count << " " << flag;
	return 0;
}
2023/11/29 23:59
加载中...