测试用例过了但10分
查看原帖
测试用例过了但10分
555584
weiming3楼主2023/2/27 21:46
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;
	string  a[101];
	int x = 0;
	int times = 0;
	while (cin >> a[x]) {
		x++;
	}
	for (int i = 0; i <= s.size() - 1; i++) {
		s[i] = tolower(s[i]);
	}
	for (int i = 0; i <= x - 1; i++) {
		a[i][0] = tolower(a[i][0]);
	}
	for (int i = 0; i <= x - 1; i++) {
		if (a[i] == (s)) {
			times++;
		}
	}
	if (times == 0) {
		cout << "-1";
	} else {
		cout << times << " ";
		if (a[0] == s) {
			cout << "0";
		} else {
			for (int i = 0; i <= x - 1; i++) {
				int count = 0;
				if ((a[i] == (s))) {
					cout << count + 1;
					break;
				} else {
					count += a[i].size() + 1;
				}
			}
		}
	}
	return 0;
}

难道要输出单词位置而不是字符的位置?

2023/2/27 21:46
加载中...