蓝桥杯备赛1.统计单词数

题目链接:P1308 [NOIP2011 普及组] 统计单词数 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

cpp 复制代码
#include<bits/stdc++.h>
#define int long long 
#define endl '\n'
const int N = 1e5+10;
using namespace std;
int a[N];
signed main()
{
    std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int sum = 0;
    string s1,s2;
	getline(cin,s1);
    getline(cin,s2);
    for(int i=0;i<s1.size();i++)
    {
    	s1[i]=tolower(s1[i]);
	}
	for(int i=0;i<s2.size();i++)
	{
		s2[i]=tolower(s2[i]);
	}
	s1 = ' '+s1+' ';
	s2 = ' '+s2+' ';
    int pos = s2.find(s1);
    if(pos==string::npos)
    {
    	cout<<-1<<endl;
	}
	else
	{
		int st = pos;
		while(st!=-1)
		{
			sum++;
			st = s2.find(s1,st+1);
		}
		cout<<sum<<' '<<pos<<endl;
	}

    
    return 0;
}
相关推荐
程序员杰哥1 天前
软件测试之压力测试详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·压力测试
橘颂TA1 天前
【剑斩OFFER】算法的暴力美学——二分查找
算法·leetcode·面试·职场和发展·c/c++
吃着火锅x唱着歌1 天前
LeetCode 1128.等价多米诺骨牌对的数量
算法·leetcode·职场和发展
小当家.1052 天前
[LeetCode]Hot100系列.贪心总结+思想总结
算法·leetcode·职场和发展
努力学算法的蒟蒻2 天前
day09(11.6)——leetcode面试经典150
算法·leetcode·职场和发展
摸鱼仙人~2 天前
针对编程面试和算法题的基础书籍
算法·面试·职场和发展
我命由我123452 天前
Photoshop - Photoshop 工具栏(24)磁性套索工具
学习·ui·职场和发展·求职招聘·职场发展·课程设计·美工
weixin_441003642 天前
2025教资面试真题电子版|科目试讲+结构化真题解析|完整PDF
面试·职场和发展·pdf
程序员三藏2 天前
Postman接口测试详解
自动化测试·软件测试·python·测试工具·职场和发展·接口测试·postman
我命由我123452 天前
Photoshop - Photoshop 工具栏(20)混合器画笔工具
经验分享·笔记·学习·ui·职场和发展·职场发展·photoshop