Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
3525 | 孙浚轩 | 统计特定单词数 | C++ | Wrong Answer | 0 MS | 264 KB | 709 | 2024-06-14 23:56:25 |
#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; for(int i=0,cnt=0;i<lens;i++){ if(essay.substr(i,lenw)==word){ if(essay[i+lenw+1]==' '||i+lenw==lens){ if(first==-1) first=i; frequency++; i+=lenw-1; } } } if(frequency) cout<<frequency<<" "<<first; else cout<<-1; return 0; }
------Input------
alun OK Alun is the best teacher of TCJY
------Answer-----
1 3
------Your output-----
-1