abcde a3aaaaaa aa#Sample Output03
-----------------------------------我是倒霉的分割線------------------------------------------------------------
思路分析:
進(jìn)行字符串匹配。
回顧總結(jié):
要熟練掌握字符串操作的一些函數(shù),和string與char*的一些特性,不要把兩者搞混了。
掌握f(shuō)ind()函數(shù)的使用,第一個(gè)參數(shù)是匹配串,第二個(gè)參數(shù)是匹配的位置。如果沒(méi)有匹配到,會(huì)返回string::npos
#include <iostream>#include<string>/* run this PRogram using the console pauser or add your own getch, system("pause") or input loop */using namespace std;int main(int argc, char** argv) { int n; string a,b; while(1) { cin>>a; if(a[0]=='#') break; cin>>b; //int loc=s.find_first_of(" "); // string a=s.substr(0,loc-1); //string b=s.substr(loc+1,s.length()-1); int count=0,begin; int size=b.length(); begin=0-size; while((begin=a.find(b,begin+size))!=string::npos) { count++; } printf("%d/n",count); } return 0;}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注