Run ID:3522
提交时间:2024-06-14 23:40:18
#include<iostream> using namespace std; void allToLC(string &s){ int lens=s.size(); for(int i=0;i<lens;i++) if(s[i]>='A'&&s[i]<='Z') s[i]+=32; } int main(){ string word,essay; cin>>word; cin.get(); getline(cin,essay); allToLC(word); allToLC(essay); int lenw=word.size(),lens=essay.size(),frequency=0,first,temp; bool d=0,d2=0; for(int i=0,cnt=0;i<lens;i++){ if(!d) temp=i; if(essay[temp+cnt]==word[cnt]){ if(!d) d=1; if(cnt==lenw-1){ if(essay[temp+cnt+1]!=' '){ if(!d2) first=temp,d2=1; frequency++,d=0,cnt=0; } }else cnt++; }else cnt=0,d=0; } if(d2) cout<<frequency<<" "<<first; else cout<<-1; return 0; }