求教,为什么这种方法过不了。样例都能过,但是提交的时候只有答案为-1时才能通过,其他数据全是WA
#include<iostream>
#include<cstring>
using namespace std;
string toUpper(string str){
for(auto &x:str) {
x = toupper(x);
}
return str;
}
int main() {
string P;
string T;
cin>>P;
int cnt = 0, loc = 0, i = 0;
while(cin>>T) {
if(toUpper(P) == toUpper(T)) {
cnt ++;
if(cnt == 1) loc = i;
}
i = i + T.size() + 1;
}
if(cnt != 0) cout<<cnt<< " " <<loc;
else cout<<"-1";
return 0;
}