关于IDE:vs没有问题,洛谷IDE输出全为-1
查看原帖
关于IDE:vs没有问题,洛谷IDE输出全为-1
385250
ZtoZero楼主2023/7/30 21:05
#include<iostream>
#include<cstring>
#include<sstream>
#include<cctype>
using namespace std;
string a1, b,c;//a1待查找单词,b给定文章,c用于判断句首空格
int t, n;//t首次出现位置,n出现次数
bool u = 1;
int main() {
	cin >> a1;
	for (int i = 0; i < a1.length(); ++i) {
		a1[i] = toupper(a1[i]);
	}//全部大写
	while (1) {
		c[0] = getchar();
		if (c[0] == ' ')++t;
		else break;
	}//读取空格并统计数量
	while (cin >> b) {
		b.insert(0, 1, c[0]);//在串首插入最后读取的字符
		c = "";
		for (int i = 0; i < b.length(); ++i) {
			b[i] = toupper(b[i]);
		}
		if (b == a1) {
			++n;
			u = 0;
		}//匹配到单词后t不再增加
		if (u)++t;
		b = "";
	}
	if (n)cout << n << ' ' << t << endl;
	else cout << -1;
	return 0;
}
2023/7/30 21:05
加载中...