#10986. 2024年信息素养大赛初赛-客观题(初中组)

0

2024年信息素养大赛初赛-客观题(初中组)

2024年全国青少年信息素养大赛初赛真题

算法创意实践挑战赛 C++初中组 试卷1


一、单项选择题(每题5分,共75分)

第1题

编写程序,计算区间100~n之间的所有整数(100 < n <= 999),数字x(0 < x < 9)共出现的次数,补全①、②和③处的代码。例如:100到109中,即100、101、102、103、104、105、106、107、108、109中,数字1出现了11次。

#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 << endl;
    return 0;
}

{{ select(1) }}

  • 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 = n; s=a/10; b =a%100;

第2题

完全数是指一个数恰好等于除它本身之外的所有因数之和。例如:6的因数有1、2、3、6,除去6之外的因数之和为1+2+3=6,所以6为完全数。编写程序,按从小到大的顺序寻找1到10000之间的完全数,输出第n个完全数,n的范围0 < 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(2) }}

  • sum +=i; sum == a; continue;
  • sum+=j; sum == a; break;
  • sum +=j; sum == a; continue;
  • sum +=i; sum == a; break;

第3题

下面哪个语句运行结果是9? {{ select(3) }}

  • cout <<"5+ 4" << endl;
  • cout << 5<<"+"<<4<< endl;
  • cout << 5+4 <<endl;
  • cin >> 5+4 >> endl;

第4题

下面代码实现的是判断n是否是质数的功能。补全①和②处的代码。

#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    ___①___
    for(int i = 2; i < n; i++){
        if(___②___){
            isprime = false;
            break;
        }
    }
    cout << isprime << endl;
    return 0;
}

{{ select(4) }}

  • bool isprime = true; n%i == 0
  • bool isprime = false; n%i!=0
  • bool isprime = true; n%i != 0
  • bool isprime = false; n%i ==0

第5题

在C++中,表示布尔数据类型的关键字是( ) {{ select(5) }}

  • int
  • bool
  • double
  • string

第6题

声明一个整型变量age的正确方式是( ) {{ select(6) }}

  • int age;
  • float age;
  • string age;
  • char age;

第7题

假设有两个城市:城市A和城市B。每个城市的温度都在-50到50摄氏度之间。当且仅当只有一个城市的温度低于0时,输出1。也就是说,如果城市A的温度低于0而城市B大于等于0;或者如果城市A的温度大于等于0而B小于0,则输出1,否则输出0。补全①和②处的代码。

#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(7) }}

  • a<0 b>=0
  • a>0 b<=0
  • a>=0 b>=0
  • a <0 b<0

第8题

运行以下程序,输出的结果是( )

#include<iostream>
using namespace std;
int main(){
    int a = 5;
    int b = a + 3;
    int c = b - 2;
    cout << c;
    return 0;
}

{{ select(8) }}

  • 6
  • 8
  • 5
  • 10

第9题

C++中有很多数据类型,以下可以定义存储浮点型变量的关键字是( ) {{ select(9) }}

  • int
  • double
  • char
  • long long

第10题

执行以下程序段,输入11,则输出的值是( )

int x;
cin >> x;
cout << x + 2;

{{ select(10) }}

  • 10
  • 11
  • x
  • 13

第11题

在C++中,表示小于或等于的关系运算符是( ) {{ select(11) }}

  • <
  • ==
  • <=
  • >

第12题

在C++中,以下正确的变量命名是( ) {{ select(12) }}

  • 2things
  • _myVariable
  • my-variable
  • None of the above

第13题

要在C++中打印"Hello,World!",以下语句正确的是( ) {{ select(13) }}

  • cout << "Hello, World!";
  • cout "Hello,World!";
  • cout << Hello, World!;
  • cout >> "Hello, World!";

第14题

小A有一个神奇口袋,里面可以装各个平方数。口袋的负载量就是口袋里所有数字之和。当负载量超过L的时候不能再装平方数。现在给定n个数,从左往右筛选其中的平方数,并依次将平方数放入口袋,编写程序,输出口袋里能装下几个平方数。平方数就是一个整数乘以自己的结果(例如: 1、4、9、16、……)补全①、②和③处的代码。

例如:输入L为100,n为5,接下来的5个数分别是49、19、36、25、73,则口袋里只装了49和36两个平方数,所以输出2。

#include<iostream>
using namespace std;
int main(){
    int L, n, cnt = 0, sum = 0;
    cin >> L >> n;
    for(int i = 1; i <= n; i++){
        int x;
        bool flag = false;
        cin >> x;
        for(int j = 1; j < x; j++){
            if(___①___){
                flag = true;
                break;
            }
        }
        if(flag == true){
            if(___②___){
                sum += x;
                cnt++;
            } else {
                ___③___
            }
        }
    }
    cout << cnt;
    return 0;
}

{{ select(14) }}

  • j*j==x sum+x<=L continue;
  • j*j==x sum+x<=L break;
  • x/j==i sum<=L continue;
  • x/j==i sum<=L break;

第15题

运行以下程序,输出的结果是( )

#include<iostream>
using namespace std;
int main(){
    cout << "Hell" << " ";
    cout << "World";
    return 0;
}

{{ select(15) }}

  • Hello,World
  • Hello World
  • 语法错误
  • 无任何输出

二、判断题(每题5分,共25分)

第16题

在C++中,整型 int 可以用来存储小数。 {{ select(16) }}

  • 正确
  • 错误

第17题

在C++中,&&|| 分别代表逻辑与和逻辑或运算。 {{ select(17) }}

  • 正确
  • 错误

第18题

在C++中,变量声明后,如果不初始化,其值是确定的。 {{ select(18) }}

  • 正确
  • 错误

第19题

在C++中,cout 用于输入,而 cin 用于输出。 {{ select(19) }}

  • 正确
  • 错误

第20题

在C++中,break 语句可以用来立即退出当前的循环。 {{ select(20) }}

  • 正确
  • 错误