P8752[蓝桥杯2021省B2]特殊年份——string提取索引转换为值
- 软件开发
- 2025-08-31 15:42:03
![P8752[蓝桥杯2021省B2]特殊年份——string提取索引转换为值](/0pic/pp_81.jpg)
这里写目录标题 链接题目代码大佬解答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
P8752[蓝桥杯2021省B2]特殊年份——string提取索引转换为值由讯客互联软件开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“P8752[蓝桥杯2021省B2]特殊年份——string提取索引转换为值”