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

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

这里写目录标题

  • 链接
  • 题目
  • 代码
  • 大佬解答
  • 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;
	else
		return 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.dtcms.com/a/24982.html

相关文章:

  • ARM系统源码编译OpenCV 4.10.0(包含opencv_contrib)
  • vue3和vue2的组件开发有什么区别
  • 3.10 企业级AI内容生成引擎:从策略到落地的全链路技术指南
  • 【大模型】Transformers基础组件 - Tokenizer
  • 2024年职高单招或高考计算机类投档线
  • Python基于Django的人脸识别上课考勤管理系统【附源码】
  • flink jobgraph详细介绍
  • Golang GORM系列:GORM并发与连接池
  • 未来游戏:当人工智能重构虚拟世界的底层逻辑
  • 【mysql】数据类型介绍-空间类型-空间索引
  • Docker换源加速(更换镜像源)详细教程(2025.2最新可用镜像,全网最详细)
  • 机械学习基础-10.从时间序列数据中学习-数据建模与机械智能课程自留
  • LabVIEW的吞雨测控系统
  • 探讨如何加快 C# 多层循环的速度效率
  • 软件测试:定义和实质
  • 观望=没有!
  • 利用websocket检测网络连接稳定性
  • MySQL 清空表的数据
  • CommonLang3-使用介绍
  • SQL知识体系
  • 统一的多摄像头3D感知框架!PETRv2论文精读
  • RV1126解码模块初始化(二)
  • 图床 PicGo+GitHub+Typora的下载安装与使用
  • 开源Web主机控制面板ISPConfig配置DNS
  • Cursor 无限续杯
  • Android平台基于SmartPlayer实现多实例RTSP|RTMP播放器
  • 从WebRTC到EasyRTC:嵌入式适配的视频通话SDK实现低延迟、高稳定性音视频通信
  • 解锁Linux“故障宝藏”:Core Dump分析秘籍(转)
  • 基于微信小程序的宿舍报修管理系统设计与实现,SpringBoot(15500字)+Vue+毕业论文+指导搭建视频
  • 解锁 Python 的 * 和 **:从参数传递到容器构建的解包技巧