每日一题(6)

第一题:旗鼓相当的对手

题解:

#include<iostream>
using namespace std;
int main()
{
	int N, count = 0;
	cout << "请输入一个正整数N:" << endl;
	cin >> N;
	int arr[100][4] = {0};
	cout << "请输入每名同学的成绩:" << endl;
	for (int i = 1; i <= N; i++)
	{
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];

		arr[i][3] = arr[i][0] + arr[i][1] + arr[i][2];
	}
	for (int i = 1; i <= N - 1; i++)
	{
		for (int j = i + 1; j <= N; j++)

		{
			if (abs(arr[i][0] - arr[j][0]) <= 5 &&
				abs(arr[i][1] - arr[j][1]) <= 5 &&
				abs(arr[i][2] - arr[j][2]) <= 5 &&
				abs(arr[i][3] - arr[j][3]) <= 10)
			{
				count++;
			}
		}
	}
	cout << "“旗鼓相当的对手”的对数为:" << count << endl;
	return 0;
}

第二题:2的幂

题解:

#include<iostream>
using namespace std;

int main()
{
	int a;
	cout << "请输入一个整数;" << endl;
	cin >> a;
	if (a % 2 == 0)
	{
		cout << "true" << endl;
	}
	else
	{
		cout << "false" << endl;
	}
	return 0;
}

 第三题:求极差/最大跨度值

题解:

 

#include<iostream>
using namespace std;

int main()
{
	int n, a[1000];
	cout << "请输入一个正整数:" << endl;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int minNum = a[0], maxNum = a[0];
	for (int i = 0; i < n; i++)
	{
		if (a[i] < minNum) 
			minNum = a[i];
		if (a[i] > maxNum) 
			maxNum = a[i];
	}
	cout << "极差为:" << maxNum - minNum << endl;
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值