第十一届蓝桥杯省赛真题(C/C++大学B组)

试题A :门牌制作

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

const int N = 100000;
int arr[N];

int main()
{
	int ans = 0,t;
	for(int i = 1;i <= 2020;i++)
	{
		t = i;
		while(t > 0)
		{
			if(t % 10 == 2) ans++;
			t /= 10;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

试题B :既约分数

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int gcd(int a,int b)
{
	if(a % b == 0) return b;
	return gcd(b,a % b);
}

int main()
{
	int ans = 0;
	for(int i = 1;i <= 2020;i++)
	{
		for(int j = 1;j <= 2020;j++)
		{
			if(gcd(i,j) == 1) ans++;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

试题C :蛇形填数

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int arr[100][100];

int main()
{
	int sum = 1; 
	for(int i = 0;i < 50;i++)
	{
		//奇数,行-,列+ 
		if(i % 2 == 1)
		{
			for(int x=i,y=1;x >= 0 && y <= i;x--,y++)
				arr[x][y] = sum++;
		}
		//偶数,行+,列-
		else
		{
			for(int x=1,y=i;x <= i && y >= 0;x++,y--)
				arr[x][y] = sum++;
		} 
	}
	cout<<arr[20][20]<<endl;
	return 0;
}
相关推荐
郝学胜_神的一滴21 小时前
CMake 30:循环语法全解|foreach_while双循环精讲、迭代技巧与实战避坑指南
c++·cmake
卷无止境3 天前
C++ 的Eigen 库全解析
c++
卷无止境3 天前
现代 C++特性大盘点:一门脱胎换骨的老语言
c++·后端
郝学胜_神的一滴3 天前
CMake 27:缓存变量的特性、语法、类型与实操全解
c++·cmake
博客18005 天前
酷宝的使用方法,超好用的免费界面库,C++、MFC可用
c++·mfc·界面库·库来帮·酷宝
郝学胜_神的一滴5 天前
CMake 026:属性体系精讲、四大作用域全解 & 实战代码落地
c++·cmake
众少成多积小致巨6 天前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
clint45610 天前
C++进阶(1)——前景提要
c++
夜悊10 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴10 天前
CMake 021: IF 条件判据详诠
c++·cmake