洛谷P1308 统计单词数(简单理解)

!!!审题!!! 图片上面写好了!!!
洛谷P1308 统计单词数(简单理解)_第1张图片
原题:题目链接点这里
思路:

1.读入字符串
(需用getline整行读入,因为cin读入到空格时会停止。)

2.转化大小写(题目不区分大小写)

3.查找空格并提取字符串(题目的要求就是完整的单词!!!)
我一开始就是错在这里,以为只要出现word就行,后来重新审题就是单独的单词!!!

4.相互比较也就是模拟!!!

#include
#define pb push_back
#define pback pop_back
#define ll long long 
using namespace std;
const ll modd=1e9+7;
const int maxn=75005;

string word,s;
vectorv;
int main(){
	getline(cin,word);             		//这个就是整行读入
	getline(cin,s);
	s=' '+s+' ';                      			//这个文章你可以加这个空格
	int la=word.size();
	int lb=s.size();
	for(int i=0;i='A'&&word[i]<='Z')
			word[i]+=32;
	for(int i=0;i='A'&&s[i]<='Z')
			s[i]+=32;
	int cnt1=0,cnt2=0;               //cnt1出现的次数    cnt2表示位置
	for(int i=0,j=0;i

个人觉得还是不要用stl库函数去做!!!毕竟模拟对你有好处!!!
很多字符串的函数:点这里

你可能感兴趣的:(Acm算法)