麻烦的题

博约8486  •  1天前


include<bits/stdc++.h>

using namespace std;

char change(char c){

char newc ;

if(c >= 'a' && c <= 'z'){
	newc = c + 'A' - 'a';
}else if(c >= 'A' && c <= 'Z'){
	newc = c - 'A' + 'a';
}

return newc;

}

int main(){

string ans, article;
getline(cin , ans);
getline(cin , article);
int flag = -1;
int j = 0;
int count = 0;
int index = 0;
for(int i = 0; i < article.length(); i++){
	int temp = i;
	while(change(ans[j]) == article[temp] || ans[j] == article[temp]){
		if(j == 0) {
			if(article[temp - 1] == ' ') ; 
			else break;
		}
		if(j == ans.length() - 1){
			if(article[temp + 1] == ' ') ; 
			else break;
		}
		//cout << "temp : " << temp << "j : " << j << endl;
		if(j + 1 == ans.length()){
			count++;
			if(flag == -1){
				flag = 1;
				index = temp + 1 - ans.length();
			}
		}
		j++;
		temp++;
	}
	j = 0;
}

if(flag == 1) cout << count << " " << index;
else cout << -1;

}


评论:

请先登录,才能进行评论