#1 本地过,洛谷RE?20分求助
查看原帖
#1 本地过,洛谷RE?20分求助
921176
leiwenjin1234楼主2023/10/18 20:12
#include<bits/stdc++.h>
using namespace std;
int len, ans1 = 0, ans2 = 0x3f3f3f;
char w[11], s[1000001];
int main() {
	fgets(w, 201, stdin);
	fgets(s, 1000001, stdin);
	for (int i = 0; i < strlen(w); i++) {
		if (w[i] >= 'A' && w[i] <= 'Z') {
			w[i] += 'a' - 'A';
		}
	}
	for (int i = 0; i < strlen(s); i++) {
		if (s[i] >= 'A' && s[i] <= 'Z') {
			s[i] += 'a' - 'A';
		}
	}//全部转小写
  int i = 0;
	while(s[i]==' '){
		i++;
	}//去多余空格
	while (1) {
		int j = i;
		bool y = 1;
		for (; s[j] != ' '; j++) {
			if (w[j - i] != s[j] || w[j - i] == ' ') {
				while (s[j] != ' ') {
					j++;
				}
				y = 0;
				break;

			}
		}
	if (y) {
			ans2 = min(ans2, i);
			ans1++;
		}
		i = j + 1;
	
		if (s[i] == ' ')break;
	}
	if (!ans1) {
		cout << "-1";
		return 0;
	}
	cout << ans1 << " " << ans2;
}
2023/10/18 20:12
加载中...