P8752 [蓝桥杯 2021 省 B2] 特殊年份——string提取索引转换为值

server/2025/2/23 1:30:04/

这里写目录标题

  • 链接
  • 题目
  • 代码
  • 大佬解答
  • string提取索引转换为值

链接

P8752 [蓝桥杯 2021 省 B2] 特殊年份

题目

在这里插入图片描述

代码

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <climits>  // 包含INT_MAX常量
#include <cctype>using namespace std;vector<int> years(5);
int num;int check(int n) {int a, b, c, d;d = n % 10;n /= 10;c = n % 10;n /= 10;b = n % 10;n /= 10;a = n;if (a == c && b + 1 == d)return 1;elsereturn 0;
}int main() {for (int i = 0; i < 5; i++) {cin >> years[i];if (check(years[i]))num++;}cout << num;return 0;
}

大佬解答

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <climits>  // 包含INT_MAX常量
#include <cctype>
using namespace std;int main() {char a, b, c, d;int nums = 0;for (int i = 0; i < 5; i++) {cin >> a >> b >> c >> d;//用于读取四位数的每一位if (a == c && b + 1 == d)nums++;}cout << nums;return 0;
}

string提取索引转换为值

	cin >> s;  cout << s[0] - '0'  << endl;

输入:2025
输出:2


http://www.ppmy.cn/server/169997.html

相关文章

《Operating System Concepts》阅读笔记:p62-p75

《Operating System Concepts》学习第 10 天&#xff0c;p62-p75 总结&#xff0c;总计 14 页。 一、技术总结 1. system call (1) 定义 The primary interface between processes and the operating system, providing a means to invoke services made available by th…

51单片机-按键

1、独立按键 1.1、按键介绍 轻触开关是一种电子开关&#xff0c;使用时&#xff0c;轻轻按开关按钮就可使开关接通&#xff0c;当松开手时&#xff0c;开关断开。 1.2、独立按键原理 按键在闭合和断开时&#xff0c;触点会存在抖动现象。P2\P3\P1都是准双向IO口&#xff0c;…

✨ 索引有哪些缺点以及具体有哪些索引类型

索引的定义与原理 索引是数据库中用于提高数据检索效率的数据结构。它就像是书籍的目录&#xff0c;通过目录可以快速定位到所需内容的页码&#xff0c;而在数据库中&#xff0c;索引可以帮助数据库系统快速找到符合查询条件的数据行&#xff0c;而不必对整个表进行扫描。 其…

可编辑112页PPT | DeepSeek行业应用实践报告

荐言分享&#xff1a;DeepSeek&#xff0c;作为一种前沿的人工智能技术&#xff0c;自其发布以来&#xff0c;已在多个行业领域展现出广泛的应用潜力和实践价值。本报告旨在全面介绍DeepSeek的技术特点、行业应用实践以及其对未来行业发展的深远影响。 DeepSeek-R1&#xff0c;…

【python】网页批量转PDF

安装wkhtmltopdf 网站&#xff1a;wkhtmltopdf wkhtmltopdf http://www.baidu.com/ D:website1.pdf 安装pdfkit库 pip install pdfkit 批量转换代码 import os import pdfkit path_wkthmltopdf rE:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe config pdfkit.configu…

wps中的js开发

严格区分大小写 /*** learn_js Macro*/ function test() {Range(D7).Value2Selection.Value2; // Selection.formula "100" }function Workbook_SheetSelectionChange(Sh, Target) {if(Sh.Name Sheet1) {test();}}function test2() {// 把I4单元格及其周边有数的单…

跨中心模型自适应牙齿分割|文献速递-医学影像人工智能进展

Title 题目 Cross-center Model Adaptive Tooth segmentation 跨中心模型自适应牙齿分割 01 文献速递介绍 三维&#xff08;3D&#xff09;口腔内扫描牙齿模型的自动、准确分割是计算机辅助正畸治疗不可或缺的先决条件。具体而言&#xff0c;口腔内扫描&#xff08;IOS&am…

JUC并发—9.并发安全集合三

大纲 1.并发安全的数组列表CopyOnWriteArrayList 2.并发安全的链表队列ConcurrentLinkedQueue 3.并发编程中的阻塞队列概述 4.JUC的各种阻塞队列介绍 5.LinkedBlockingQueue的具体实现原理 6.基于两个队列实现的集群同步机制 1.并发安全的数组列表CopyOnWriteArrayList …