蓝桥杯备赛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;
}
相关推荐
qq_459234423 天前
【题库】| 商用密码应用安全性评估从业人员考核题库(四十)
职场和发展·密码学·学习方法·考核·商用密码·商用密码应用安全性评估·密评
敲敲了个代码3 天前
[特殊字符] 空数组的迷惑行为:为什么 every 为真,some 为假?
前端·javascript·react.js·面试·职场和发展
诚思报告YH3 天前
视频面试软件市场洞察:2026 - 2032年复合年均增长率(CAGR)为10.3%
面试·职场和发展
重生之后端学习3 天前
74. 搜索二维矩阵
开发语言·数据结构·算法·职场和发展·深度优先
tyb3333333 天前
leetcode:吃苹果和队列
算法·leetcode·职场和发展
Pitiless-invader3 天前
MySQL 相关知识及面试问题汇总
面试·职场和发展
重生之后端学习3 天前
35. 搜索插入位置
java·数据结构·算法·leetcode·职场和发展·深度优先
逆境不可逃3 天前
【从零入门23种设计模式08】结构型之组合模式(含电商业务场景)
线性代数·算法·设计模式·职场和发展·矩阵·组合模式
筱昕~呀3 天前
冲刺蓝桥杯-DFS板块(第二天)
算法·蓝桥杯·深度优先
zheshiyangyang3 天前
前端面试基础知识整理【Day-10】
前端·面试·职场和发展