Run ID:58011
提交时间:2023-09-16 21:49:23
#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; }