#1562. 信息素养大赛模拟卷

信息素养大赛模拟卷

单项选择题,每个 55 分。

  1. 执行以下程序段,输入 1111,输出是()
int x;
cin >> x;
cout << x + 2;

{{ select(1) }}

  • 1010
  • 1111
  • xx
  • 1313
  1. C++ 中,输入指令是()

{{ select(2) }}

  • cout
  • cin
  • clog
  • int
  1. 假设有两个城市:城市 AA 和城市 BB。每个城市的温度都在 50°50°-50°\sim 50° 之间,当且仅当只有一个城市的温度低于 0° 时,输出 11,也就是说,如果 AA 的温度低于 00 且城市 BB 大于等于 00;或者如果城市 AA 的温度大于等于 00BB 小于 00,则输出 11,否则输出 00,请你补全下面代码的两处空缺。
#include <iostream>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (__)
    {
        if (__)
        {
            cout << 1;
            return 0;
        }
    }
    if (a >= 0)
    {
        if (b < 0)
        {
            cout << 1;
            return 0;
        }
    }
    cout << 0;
    return 0;
}

{{ select(3) }}

  • a < 0 b >= 0
  • a > 0 b <= 0
  • a >= 0 b >= 0
  • a < 0 b < 0
  1. C++ 中,表示布尔数据类型的关键字是()

{{ select(4) }}

  • int
  • bool
  • double
  • string
  1. 完全数指的是一个数恰好等于除它本身之外的所有因数之和,例如:66 的因数有 1,2,3,61,2,3,6,除去 66 以外的因数之和为 1+2+3=61+2+3=6,因此 66 是完全数。编写程序,按从小到大的顺序寻找 11041\sim 10^4 之间的完全数,输出第 nn 个完全数,0<n<50<n<5,补全三处代码。
#include <iostream>
using namespace std;
int main()
{
    int n, sum = 0, num = 0;
    cin >> n;
    for (int i = 1; i < 10000; i++)
    {
        int a = i;
        sum = 0;
        for (int j = 1; j < a; j++)
        {
            if (a % j == 0)
            {
                ___
            }
        }
        if (___)
        {
            num++;
        }
        if (num == n)
        {
            cout << a;
            ____
        }
    }
    return 0;
}

{{ select(5) }}

  • sum += i; sum == a continue;
  • sum += j; sum == a break;
  • sum += j sum !+= a continue;
  • sum += i; sum == a break;
  1. 以下可以作为变量名的是 ( )。

{{ select(6) }}

  • cnt_1
  • 1_cnt
  • cnt1_#
  • @cnt
  1. C++ 中有很多数据类型,以下可以定义存储浮点型变量的关键字是()

{{ select(7) }}

  • int
  • double
  • char
  • long long
  1. 如果我们想在终端输出变量 xx 的值,正确的代码是() {{ select(8) }}
  • cin >> x
  • cin << x
  • cout << x
  • cout >> x
  1. 执行以下代码段,变量 xxyy 的值分别是()
int x = 7;
int y = x / 2 * 3;

{{ select(9) }}

  • x = 7, y = 10.5
  • x = 7, y = 10
  • x = 7, y = 12
  • x = 7, y = 9
  1. 执行以下代码,输出的结果是()
int x = 5, y = 3;
cout << (x > y);

{{ select(10) }}

  • true
  • false
  • 1
  • 2
  1. C++ 中,如果用两个 int 类型的变量 lengthwidth 分别表示长方形的长和宽,则可以用来计算长方形面积的表达式是()。

{{ select(11) }}

  • length * width
  • length + width
  • (length + width) / 2
  • length * 2 + width * 2
  1. 数字直角三角形:给出 nn,输出一个直角边长为 nn 的数字直角三角形,所有数字都是 22 位组成的,如果没有 22 位则加上前导 00,试补全 ① 和 ② 的代码。

例如当 n=5n=5 的数字三角形如下所示

01
0203
040506
07080910
1112131415
#include <iostream>
using namespace std;
int main()
{
    int n, cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1;__①__; j++)
        {
            cnt++;
            if (__②__)
            {
                cout << 0;
            }
            cout << cnt;
        }
        cout << endl;
    }
    return 0;
}

{{ select(12) }}

  • j <= n cnt < 10
  • j <= n cnt > 10
  • j <= i cnt < 10
  • j <= i cnt > 10
  1. 编写程序,计算区间 100n100\sim n 之间的所有整数( 100<n<=999100<n<=999 ),数字 xx (0<x<90<x<9) 共出现的次数。补全 ①、② 和 ③ 处的代 码。

例如:100100109109 中,即 100101102103104105106107108109100、101、102、103、104、105、106、107、108、109 中,数字 11 出现了 1111 次。

#include <iostream>
using namespace std;
int main()
{
    int n, x, cnt = 0;
    cin >> n >> x;
    for (int i = 100; i <= n; i++)
    {
        _①_
        int g, s, b;
        g = a % 10;
        __②__
        __③__
        if (g == x) 
        {
            cnt++;
        }
        if (s == x)
        {
            cnt++;
        }
        if (b == x)
        {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

{{ select(13) }}

  • int a = i; s = a / 10 % 10; b = a / 100;
  • int g = i; s = g % 10; b = g % 100;
  • int cnt = i; s = cnt % 10; b = cnt / 100;
  • int a = b; s = a / 10; b = a % 100;
  1. 运行下列程序段,输出的结果是()。
int n = 572765;
cout << n / 10 % 10;

{{ select(14) }}

  • 55
  • 66
  • 44
  • 11
  1. 下列关于C++ 语言中变量的叙述,不正确的是() {{ select(15) }}
  • 变量定义时可以不初始化
  • 变量被赋值之后的类型不变
  • 变量没有定义也能够使用
  • 变量名必须是合法的标识符

判断题,每个 55 分。

  1. C++ 中,变量声明后,如果不初始化,其值是确定的。

{{ select(16) }}

  • 正确
  • 错误
  1. C++ 中,== 是赋值运算符。

{{ select(17) }}

  • 正确
  • 错误
  1. C++ 中,整型 int 可以用来存储小数。

{{ select(18) }}

  • 正确
  • 错误
  1. C++ 中,所有变量都必须在使用前声明其数据类型。

{{ select(19) }}

  • 正确
  • 错误
  1. C++ 中,变量名可以以字母或下划线开头。

{{ select(20) }}

  • 正确
  • 错误