题目:实现string的除法
判断str1中str2出现的次数?
#include "stdafx.h"
#include<string>
#include <iostream>
using namespace std;
int chufa(string longstr,string shortstr)
{
int count = 0;
int index = 0;
int shortlen = shortstr.length();
while (longstr.find(shortstr,index)!=-1)
{
count++;
index = longstr.find(shortstr,index);
index+=shortlen;
}
return count;
}
int _tmain(int argc, _TCHAR* argv[])
{
string str1,str2;
cin>>str1>>str2;
cout<<chufa(str1,str2);
return 0;
}