Run ID:3528
提交时间:2024-06-15 00:13:55
#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=-1,d; for(int i=0,temp=lens-lenw;i<=temp;i++){ if(essay.substr(i,lenw)==word){ d=0; if(essay[i-1]==' ') d++; if(essay[i+lenw]==' ') d++; if(i==0) d++; if(i+lenw==lens) d++; if(d==2){ if(first==-1) first=i; frequency++; i+=lenw-1; } } } if(frequency) cout<<frequency<<" "<<first; else cout<<-1; return 0; }