80pts 求助
查看原帖
80pts 求助
255169
__LePetitPrince__楼主2022/6/30 21:16

好像是很长的就找不到

#include <iostream>
#include <string>
using namespace std;
string w;
char toCap(char c) {
	if (c >= 'a' && c <= 'z') c -= ('a' - 'A');
	return c;
}
int main() {
	cin >> w;
	for (int i = 0; i < w.size(); i++) {
		w[i] = toCap(w[i]);
	}
	string x = "";
	char c;
	int idx = 0, cnt = 0;
	bool find = false;
	c = getchar();
	while (true) {
		c = getchar();
		if (c == EOF) break;
//		cout << c << endl;
		if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
			x += toCap(c);
			if (!find) idx++;
		} else {
			if (x == w) {
				cnt++;
				idx = idx - x.size() + 1;
				find = true;
			}
			if (!find) idx++;
			x = "";
		}
	}
	if (find) {
		cout << cnt << ' ';
		if (idx != 0) cout << idx - 1;
		else cout << idx;
	} else cout << -1;
	return 0;
}
2022/6/30 21:16
加载中...