当前位置: 首页 > news >正文

做网站和自媒体哪个好厦门seo全网营销

做网站和自媒体哪个好,厦门seo全网营销,政府门户网站建设发展的看法,企业互联网整合营销🍭 大家好这里是清隆学长 ,一枚热爱算法的程序员 ✨ 本系列打算持续跟新华为OD-C/D卷的三语言AC题解 💻 ACM银牌🥈| 多次AK大厂笔试 | 编程一对一辅导 👏 感谢大家的订阅➕ 和 喜欢💗 &#x1f…

🍭 大家好这里是清隆学长 ,一枚热爱算法的程序员

✨ 本系列打算持续跟新华为OD-C/D卷的三语言AC题解

💻 ACM银牌🥈| 多次AK大厂笔试 | 编程一对一辅导

👏 感谢大家的订阅➕ 和 喜欢💗

📎在线评测链接

单词大师(100分)

🌍 评测功能需要 订阅专栏 后私信联系清隆解锁~

🍓OJ题目截图

在这里插入图片描述

文章目录

    • 📎在线评测链接
    • 🍓OJ题目截图
    • 🥮 单词大师
      • 问题描述
      • 输入格式
      • 输出格式
      • 样例输入
      • 样例输出
      • 样例输入
      • 样例输出
      • 样例输入
      • 样例输出
      • 数据范围
      • 题解
      • 参考代码

🥮 单词大师

问题描述

给定一个字符串数组 w o r d s words words 和一个字符串 c h a r s chars chars。如果可以用 c h a r s chars chars 中的字母拼写出 w o r d s words words 中的某个单词,则认为你掌握了这个单词。 w o r d s words words 中的字符仅由小写字母 a − z a-z az 和特殊字符 ? 组成,其中 ? 可以代表任意一个字母。

注意:拼写时, c h a r s chars chars 中的每个字母只能使用一次,? 也只能使用一次。

请输出你能够拼写出的 w o r d s words words 中的单词数量。如果一个也拼写不出,则输出 0 0 0

输入格式

第一行输入一个整数 N N N,表示数组 w o r d s words words 的长度。

接下来 N N N 行,每行输入一个字符串,表示 w o r d s words words 中的一个单词。

最后一行输入一个字符串 c h a r s chars chars

其中, 1 ≤ N ≤ 100 1 \le N \le 100 1N100 1 ≤ w o r d [ i ] . l e n g t h , c h a r s . l e n g t h ≤ 100 1 \le word[i].length, chars.length \le 100 1word[i].length,chars.length100

输出格式

输出一个整数,表示你能够拼写出的 w o r d s words words 中的单词数量。

样例输入

4
cat
bt
hat
tree
atach??

样例输出

3

样例输入

3
hello
world
cloud
welldonehoneyr

样例输出

2

样例输入

3
apple
car
window
welldoneapplec?

样例输出

2

数据范围

  • 1 ≤ N ≤ 100 1 \le N \le 100 1N100
  • 1 ≤ w o r d [ i ] . l e n g t h , c h a r s . l e n g t h ≤ 100 1 \le word[i].length, chars.length \le 100 1word[i].length,chars.length100

题解

这道题可以通过统计字符频率的方式来判断是否能拼写出每个单词。

  1. 首先统计 c h a r s chars chars 中每个字母出现的次数,以及 ? 出现的次数。
  2. 对于每个单词 w o r d word word,统计其中每个字母出现的次数。
  3. 遍历单词的每个字母,如果该字母在 c h a r s chars chars 中出现的次数大于等于在 w o r d word word 中出现的次数,则可以拼写;否则,如果 ? 的数量大于等于不足的字母数,也可以拼写;否则,无法拼写该单词。
  4. 如果能拼写该单词,则答案加一。
  5. 最后输出答案即可。

时间复杂度为 O ( N L ) O(NL) O(NL),其中 N N N 为单词数量, L L L 为单词的平均长度。空间复杂度为 O ( 1 ) O(1) O(1),因为只需要常数级的额外空间。

参考代码

  • Python
n = int(input())
words = []
for _ in range(n):words.append(input())
chars = input()def can_spell(word, chars):cnt_word = [0] * 26for c in word:cnt_word[ord(c) - ord('a')] += 1cnt_chars = [0] * 26wild = 0for c in chars:if c == '?':wild += 1else:cnt_chars[ord(c) - ord('a')] += 1for i in range(26):if cnt_word[i] > cnt_chars[i]:if wild >= cnt_word[i] - cnt_chars[i]:wild -= cnt_word[i] - cnt_chars[i]else:return Falsereturn Trueans = 0
for word in words:if can_spell(word, chars):ans += 1print(ans)
  • Java
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();String[] words = new String[n];for (int i = 0; i < n; i++) {words[i] = sc.next();}String chars = sc.next();int ans = 0;for (String word : words) {if (canSpell(word, chars)) {ans++;}}System.out.println(ans);}private static boolean canSpell(String word, String chars) {int[] cntWord = new int[26];for (char c : word.toCharArray()) {cntWord[c - 'a']++;}int[] cntChars = new int[26];int wild = 0;for (char c : chars.toCharArray()) {if (c == '?') {wild++;} else {cntChars[c - 'a']++;}}for (int i = 0; i < 26; i++) {if (cntWord[i] > cntChars[i]) {if (wild >= cntWord[i] - cntChars[i]) {wild -= cntWord[i] - cntChars[i];} else {return false;}}}return true;}
}
  • Cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;bool canSpell(string word, string chars) {vector<int> cntWord(26, 0);for (char c : word) {cntWord[c - 'a']++;}vector<int> cntChars(26, 0);int wild = 0;for (char c : chars) {if (c == '?') {wild++;} else {cntChars[c - 'a']++;}}for (int i = 0; i < 26; i++) {if (cntWord[i] > cntChars[i]) {if (wild >= cntWord[i] - cntChars[i]) {wild -= cntWord[i] - cntChars[i];} else {return false;}}}return true;
}int main() {int n;cin >> n;vector<string> words(n);for (int i = 0; i < n; i++) {cin >> words[i];}string chars;cin >> chars;int ans = 0;for (string word : words) {if (canSpell(word, chars)) {ans++;}}cout << ans << endl;return 0;
}
http://www.fp688.cn/news/162852.html

相关文章:

  • 做设计网站模块的网站网站开发报价方案
  • 嵌入式工程师月薪多少搜索引擎优化英文简称为
  • 宝安专业做网站网络推广的概念
  • 企业网站怎么建设百度95099怎么转人工
  • 深圳营销型网站制作公司网页模板怎么用
  • 公司如何做网站百度浏览器官方下载
  • 网站建设电话客服话术江苏关键词推广seo
  • 商城网站里可以再放cms吗新手学seo
  • 兖州网站制作中国楼市最新消息
  • 网站商城定制网站建设网站建设的步骤
  • 深圳龙岗疫情防控日照网站优化公司
  • 东营建设信息网站怎么创建网址
  • 湖南网站建设小公司排名域名查询ip
  • 邪恶网站源码苏州优化排名seo
  • 文友胜做的网站谷歌搜索引擎网址
  • 各种类型网站建设售后完善百度认证考试
  • 电子商务网站建设可运用的技术游戏推广员好做吗
  • 网页设计感十足的网站天津百度快速排名优化
  • 设计工资一般多少南京seo排名
  • 不用关网站备案外贸推广平台哪个好
  • 网站的具体内容职业培训机构排名
  • 做外语网站的公司seo的基本内容
  • 柬埔寨网站开发洛阳网站建设优化
  • wordpress没有页面模板安卓优化大师清理
  • 免费建.com的网站seo招聘信息
  • 广告设计公司实践报告广州seo招聘
  • 网站自动收录最近一周的时政热点新闻
  • 免费网页游戏手机版全网优化推广
  • 折再返怎么 做网站指数是什么
  • 网站的用户注册怎么做企业策划