Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
3567 | 孙浚轩 | 统计特定单词数 | C++ | Accepted | 0 MS | 264 KB | 845 | 2024-06-15 14:43:26 |
#include<iostream> using namespace std; void allToLC(string &s,int lens){ 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); int lenw=word.size(),lens=essay.size(),frequency=0,first=-1,d; allToLC(word,lenw); allToLC(essay,lens); 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; }