20分求助2,完全不知道错哪里了
查看原帖
20分求助2,完全不知道错哪里了
714660
mit____楼主2024/4/12 18:59
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
	string s1,s2; getline(cin, s1); getline(cin,s2); //输入字符串
	//变成小写
	transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
	transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
	
	//以空格分割
	vector <string> words;
	vector <int> index;
	string word;
	stringstream ss(s2);
	while(ss >> word){
		words.push_back(word);
	} 
	int cnt = 0;
	for(int i = 0; i < words.size(); ++i){
//		cout << words[i] << endl;
		if(s1 == words[i]){
			cnt++;
			index.push_back(i);
		}
	}
	if(cnt == 0) cout << -1;
	else cout << cnt << " " << index[0];
	return 0;
} 
2024/4/12 18:59
加载中...