?!
by MARSandEARTH @ 2023-07-30 21:16:06
@[ZtoZero](/user/385250) 读取完 `a1` 后再读取一个字符是换行,所以 `c[0]` 一直为 `'\n'`
另外两个单词之间不一定只有一个空格
by Argvchs @ 2023-07-30 21:23:05
@[Argvchs](/user/533270) 谢谢大佬,已关
by ZtoZero @ 2023-07-31 10:12:24
重写了代码,这次终于AC了
```cpp
#include<iostream>
#include<cstring>
#include<sstream>
#include<cctype>
using namespace std;
string a1, b;
int l = 0;
int n,t;
bool u = 1;
int main() {
getline(cin, a1);
for (auto& d : a1) d = toupper(d);
getline(cin, b);
b.insert(0,1, ' ');
b.insert(b.length(), 1, ' ');
for (auto& d : b) d = toupper(d);
while (1) {
decltype(b.npos) pos = b.find(a1, l);
if (pos == b.npos) break;
else {
if (b[pos - 1] == ' ' && b[pos + a1.length()]==' ') {
++n;
if (u) t = pos;
u = 0;
}
}
l = pos + a1.length();
}
if (n) cout << n << ' ' << t-1 << endl;
else cout << -1 << endl;
return 0;
}
```
by ZtoZero @ 2023-07-31 10:13:16
我和你相反,我洛谷测试是对的但到了本地就错了。。。
by bowenzuo @ 2023-08-04 20:20:30
@[bowenzuo](/user/757822) 左博文,我看到你在L3群里问了
by Robots75 @ 2023-08-09 14:52:27