蓝桥杯——基础练习1-5

C++菜鸡选手临阵磨枪的自我记录

basic-1 基础练习 闰年判断
#include<iostream>
using namespace std;

int main()
{
	int y;
	//cout << "请输入年份: " << endl;
	cin >> y;
	if (((y % 4 == 0) && (y % 100 != 0))||(y%400==0))
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" << endl;
	}


	system("pause");
	return 0;
}
basic-2 基础练习 01字串
#include<iostream>
using namespace std;

int main() 
{
	int a, b, c, d, e;
	for (a = 0; a < 2; ++a) {
		for (b = 0; b < 2; ++b) {
			for (c = 0; c < 2; ++c) {
				for (d = 0; d < 2; ++d) {
					for (e = 0; e < 2; ++e) {
						cout << a << b << c << d << e << endl;
					}
				}
			}
		}
	}

	system("pause");
	return 0;
}
basic-3 基础练习 字母图形
#include<iostream>
using namespace std;

int main() 
{
	char a[26][26];
	int n, m;
	cin >> n >> m;
	
	for (int j = 0; j < m; j++)
	{
		a[0][j] = 'A' + j;
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i <= j)
			{
				a[i][j] = a[i - 1][j] - 1; 

			}
			else if (i > j)
			{
				a[i][j] = a[i - 1][j] + 1;
			}
			
		}
		
	}

	for (int i = 0;  i < n; i++)
	{
		for (int j = 0;  j < m; j++)
		{
			cout << a[i][j];
		}
		cout << endl;
	}




	system("pause");
	return 0;
}
basic-4 基础练习 数列特征
#include<iostream>

#include<algorithm>
using namespace std;

int main() 
{
	int n;
	int MAX = 0;
	int MIN = 0;
	int sum = 0;

	cin >> n;
	int arr[10001];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	sort(arr, arr + n);
	
	MAX = arr[n-1];
	MIN = arr[0];
	for (int i = 0; i < n; i++)
	{
		sum = sum + arr[i];
	}
	
	cout << MAX << endl;
	cout << MIN << endl;
	cout << sum << endl;
	

	system("pause");
	return 0;
}
basic-5 基础练习 查找整数
#include<iostream>
#include<algorithm>

using namespace std;


int main() 
{
	int n, a;
	cin >> n;
	int arr[1001];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	cin >> a;
	int flag = 0;
	int num;
	for (int i = 0; i < n; i++)
	{
		if (arr[i] == a)
		{
			flag = 1;
			num = i+1;
			break;
		}
	}

	if (flag == 1)
	{
		cout << num << endl;
	}
	else
	{
		cout << "-1" << endl;
	}

	system("pause");
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值