Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
58011 王嘉瑜 统计特定单词数 C++ Accepted 3 MS 276 KB 654 2023-09-16 21:49:23

Tests(11/11):


Code:

#include <iostream> #include <string> using namespace std; int main(){ string word; string text; getline(cin,word); getline(cin,text); for(int i=0;i<word.size();i++) if(word[i]>='A'&&word[i]<='Z') word[i]+=32; for(int i=0;i<text.size();i++) if(text[i]>='A'&&text[i]<='Z') text[i]+=32; word = " "+word+" "; text = " "+text+" "; if(text.find(word)!=-1){ int first_pos = text.find(word); int cnt = 0; while(text.find(word)!=-1){ int start = text.find(word); text.replace(start,word.length()," "); cnt++; } cout<<cnt<<" "<<first_pos; } else{ cout<<-1; } return 0; }