7.统计单词数
题目:
代码:
include
include
include
using namespace std;
int main(){
string intend,passage;
int num = 0,first = 0;
getline(cin,intend);
getline(cin,passage);//输入
for(int i = 0; i < intend.size();i++){
intend[i] = tolower(intend[i]);
}
for(int i = 0; i < passage.size();i++){
passage[i] = tolower(passage[i]);
}//统一格式
intend = intend.append(“ “); //a=’ ‘+a+’ ‘;
b=’ ‘+b+’ ‘;//简单写法
intend = intend.insert(0,” “);
passage = passage.append(“ “);
passage = passage.insert(0,” “);
first = passage.find(intend);
int z = first;
if(first < 0){
cout<
string str(passage,z + intend.size() - 1,passage.size() - 1);
z = str.find(intend);
passage = str;
num++;
}
cout<<num<<” “<<first;
return 0;
}