欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > 蓝桥杯2025年第十六届省赛真题-水质检测

蓝桥杯2025年第十六届省赛真题-水质检测

2025/5/9 12:13:29 来源:https://blog.csdn.net/CQY0531/article/details/147765133  浏览:    关键词:蓝桥杯2025年第十六届省赛真题-水质检测

C语言代码:

#include <stdio.h>
#include <string.h>#define MAX_LEN 1000000int main() {char a[MAX_LEN + 1], b[MAX_LEN + 1];// 使用 scanf 读取字符数组scanf("%s", a);scanf("%s", b);int ans = 0;int pre = -1;int state = -1;int len = strlen(a);for (int i = 0; i < len; i++) {if (a[i] == '.' && b[i] == '.') continue;if (pre != -1) ans += i - pre - 1;if (a[i] == '#' && b[i] == '#') state = 3;else if (a[i] == '#' && b[i] == '.') {if (state == 2) {ans++;state = 3;} else state = 1;} else if (a[i] == '.' && b[i] == '#') {if (state == 1) {ans++;state = 3;} else state = 2;}pre = i;}// 使用 printf 输出结果printf("%d", ans);return 0;
}

C++代码:

#include <iostream>
#include <string>
using namespace std;int main() {string a, b;// 使用 cin 读取 string 类型变量cin >> a >> b;int ans = 0;int pre = -1;int state = -1;for (int i = 0; i < a.size(); i++) {if (a[i] == '.' && b[i] == '.') continue;if (pre != -1) ans += i - pre - 1;if (a[i] == '#' && b[i] == '#') state = 3;else if (a[i] == '#' && b[i] == '.') {if (state == 2) {ans++;state = 3;} else state = 1;} else if (a[i] == '.' && b[i] == '#') {if (state == 1) {ans++;state = 3;} else state = 2;}pre = i;}// 使用 cout 输出结果cout << ans;return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词