#GOBJ305H. GESP 3级客观题|枚举算法|课后作业

GESP 3级客观题|枚举算法|课后作业

GESP 3级客观题|枚举算法|课后作业

考试频率:高频。本卷共 4 题。

  1. 著名的哥德巴赫猜想:任⼀⼤于2的偶数都可写成两个素数之和。我们可以通过枚举法来证明它。

    {{ select(1) }}

  1. 下面C++代码可以计算1到100的累加和,采用的是穷举法。( )
int main()
{
     int i,sum=0;
     for(int i = 1; i <= 100 ; i++)
          sum += i;
     cout << sum << endl;

     cout << endl;
     return 0;
}

{{ select(2) }}

  1. 把整数3025从中剪开分为30和25两个数,此时再将这两数之和平方,计算结果又等于原数。(30 + 25) × (30+ 25) = 55 × 55 = 3025,这样的数叫“雷劈数”。可以使用枚举的方法求出所有符合这样条件的四位数。( )

    {{ select(3) }}

  1. 下面枚举法查找最大值索引程序中,横线处应该填写的是()
#include <iostream>
using namespace std;
int main()
{
    int arr[] = {3, 7, 2, 9, 5};
    int maxIndex = 0;
    for (int i = 1; i < 5; i++)
    {
        ————————————
        {
            maxIndex = i;
        }
    }
    cout << maxIndex;
    return 0;
}

{{ select(4) }}

  • if (arr[maxIndex] > arr[i])
  • if (arr[i]-1 > arr[maxIndex])
  • if (arr[i]+1 > arr[maxIndex])
  • if (arr[i] > arr[maxIndex])
蜀ICP备2025119001号-1