求大佬帮忙看下为什么re

P1308 [NOIP2011 普及组] 统计单词数

全部re了,样例和第一个点都试过答案是对的
by DrDDs @ 2024-03-02 10:43:57


这是我的代码,可以参考一下 ```cpp #include<bits/stdc++.h> using namespace std; int main(){ string a,b; bool flag=1; int lena,lenb,total=0,pos=-1; getline(cin,b); getline(cin,a); lena=a.length(); lenb=b.length(); for(int i=0;i<lenb;i++){ b[i]=char(tolower(b[i])); } for(int i=0;i<lena;i++){ if(a[i]!=' '){ a[i]=char(tolower(a[i])); } } for(int i=0;i<lena;i++){ if(a[i]!=' '){ string s; int j=i,cnt=0; while(a[j]!=' '){ s+=a[j]; j++; cnt++; } if(b==s){ if(flag){ pos=i; flag=0; } total++; } i=i+cnt; } } if(total==0){ cout<<-1; return 0; } cout<<total<<" "<<pos; return 0; } ```
by Robin_in_luogu @ 2024-03-02 10:59:06


@[DrDDs](/user/1101971) 试一试关掉O2优化
by Hootime @ 2024-03-02 11:45:19


@[Hootime](/user/1275540) 还是不行TT
by DrDDs @ 2024-03-02 11:52:08


@[Robin_in_luogu](/user/1068165) 好的!感谢!!
by DrDDs @ 2024-03-02 11:52:25


|