当前位置: 首页 > 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

相关文章:

  • 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知识体系
  • 超新星|18岁冲击中超金靴,王钰栋的未来无限可能
  • 中医的千年传承:网络科学描绘其演化之路|PNAS速递
  • 从采购到销售!市场监管总局指导行业协会防控肉品风险
  • 网红街区如厕难,如何多管齐下补缺口?
  • 央行谈MLF:逐步退出政策利率属性回归流动性投放工具
  • 深圳两家会所涉卖淫嫖娼各被罚7万元逾期未缴,警方发催告书