害!求求帮忙看看while吧!!左测右测还是while那里的问题!
查看原帖
害!求求帮忙看看while吧!!左测右测还是while那里的问题!
342874
刘奶奶喝水呢楼主2021/2/18 16:55
#include<iostream>
#include<cstdio>
#include <string>
#include<ctype.h>
using namespace std;

//唉 本地都没通过
//这可咋整
//首先输入就不对,cin遇到空格就停止了

int main() {
	string a,part;  
	/*cin >> part;
	cin >> a;*/
	getline(cin, part);
	getline(cin, a);
	
	int testp = part.length();        
	int testa = a.length();
	//cout << testp<<endl<<testa;          //输出没错的
	for (int i = 0; i < testp; i++) {        
		part[i] = tolower(part[i]);            //因为tolower(char c)括号里应该是字符
	}
	for (int i = 0; i < testa; i++) {
		a[i] = tolower(a[i]);            //因为tolower(char c)括号里应该是字符
	}

	//坑处来也    需要在待查找字符串和源字符串两端都加上空格
	part = ' '+ part + ' ';
	a = ' ' + a + ' ';

	int index = 0;
	int sum = 0;
	index = a.find(part, index);
	cout << index<<" " ;
	index += 1;
	while (index <= testa) {              //到这里好像就死循环了  为啥呢
		index = a.find(part, index)+1;
		sum++;
	}
	cout << sum;

	return 0;
}
2021/2/18 16:55
加载中...