求助 20分
查看原帖
求助 20分
772284
Justskr楼主2023/8/18 19:17
#include<bits/stdc++.h>
using namespace std;
#define int long long
string s;
string todo;
int cnt,sum,first;
bool o;
signed main(){
	getline(cin,todo);
	getline(cin,s);
	for(int i = 0;i < s.size();i++){
		if(i == 0){
			cnt = 0;
			for(int j = 0;j <= todo.size();j++){
				if(j == todo.size()){
					if(s[i+j] == ' '){
						cnt++;
						break;
					}else{
						break;
					}
				}
				if(tolower(s[i+j]) != tolower(todo[j])) break;
				cnt++;
			}	
			if(cnt == todo.size()+1){
				if(!o){
					o = 1;
					first = 0;
										
				}
				sum++;
			}
		}
		else if(s[i] == ' '){
			cnt = 0;
			for(int j = 0;j <= todo.size();j++){
				if(j == todo.size()){
					if(s[i+j+1] == ' '){
						cnt++;
						break;
					}else{
						break;
					}
				}
				if(tolower(s[i+j+1]) != tolower(todo[j])) break;

				cnt++;
			}
			if(cnt == todo.size()+1){
				if(!o){
					o = 1;
				}
				sum++;		
			}
		}

	}
	if(!o){
		cout << -1;
		return 0;
	}
	cout << sum << " " << first;

	return 0;
	
}

没加注释,望大佬耐心看看

2023/8/18 19:17
加载中...