蓝桥杯备赛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;
}
相关推荐
火车叨位去194918 小时前
力扣top100(day04-05)--堆
算法·leetcode·职场和发展
qq_513970441 天前
力扣 hot100 Day76
算法·leetcode·职场和发展
程序员曦曦2 天前
10:00开始面试,10:06就出来了,问的问题有点变态。。。
自动化测试·软件测试·功能测试·程序人生·面试·职场和发展
是乐谷2 天前
阿里云杭州 AI 产品法务岗位信息分享(2025 年 8 月)
java·人工智能·阿里云·面试·职场和发展·机器人·云计算
天才测试猿2 天前
常见的Jmeter压测问题
自动化测试·软件测试·python·测试工具·jmeter·职场和发展·压力测试
墨染点香2 天前
LeetCode 刷题【43. 字符串相乘】
算法·leetcode·职场和发展
_不会dp不改名_2 天前
leetcode_42 接雨水
算法·leetcode·职场和发展
小木话安全2 天前
ISO27001 高阶架构 之 支持 -2
网络·安全·职场和发展·学习方法
独行soc2 天前
2025年渗透测试面试题总结-18(题目+回答)
android·python·科技·面试·职场和发展·渗透测试
gzzeason3 天前
LeetCode Hot100:递归穿透值传递问题
算法·leetcode·职场和发展