第一题:旗鼓相当的对手
题解:
#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;
}