首页 › 试卷 › C/C++编程考级 › C/C++编程二级 › 青少年软件编程(C语言二级)等级考试试卷(2021年3月)

青少年软件编程(C语言二级)等级考试试卷(2021年3月) VIP

C/C++编程二级 共 5 题 2021 年 含标准答案与解析
返回试卷列表
本页为整卷浏览:先自己做一遍,再展开「查看答案与解析」核对。

一、简答题

1. 简答题

石头剪刀布

石头剪刀布是常见的猜拳游戏。石头胜剪刀,剪刀胜布,布胜石头。如果两个人出拳一样,则不分胜负。

一天,小A和小B正好在玩石头剪刀布。已知他们的出拳都是有周期性规律的,比如:“石头-布-石头-剪刀-石头-布-石头-剪刀……”,就是以“石头-布-石头-剪刀”为周期不断循环的。请问,小A和小B比了N轮之后,谁赢的轮数多?

时间限制:1000

内存限制:65536

输入

输入包含三行。 第一行包含三个整数:N,NA,NB,分别表示比了N轮,小A出拳的周期长度,小B出拳的周期长度。0 < N,NA,NB < 100。 第二行包含NA个整数,表示小A出拳的规律。 第三行包含NB个整数,表示小B出拳的规律。 其中,0表示“石头”,2表示“剪刀”,5表示“布”。相邻两个整数之间用单个空格隔开。

输出

输出一行,如果小A赢的轮数多,输出A;如果小B赢的轮数多,输出B;如果两人打平,输出draw。

样例输入

10 3 4
0 2 5
0 5 0 2

样例输出

A

提示

对于测试数据,猜拳过程为: A:0 2 5 0 2 5 0 2 5 0 B:0 5 0 2 0 5 0 2 0 5 A赢了4轮,B赢了2轮,双方打平4轮,所以A赢的轮数多。

查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;stdio.h&gt; int N, NA, NB, i, A[200], B[200], Y = 0; int judge(int A, int B) {   int x;   switch (A) {   case 0:     x = (B == 2 ? 1 : -1);     if (B == 0)       x = 0;     break;   case 2:     x = (B == 5 ? 1 : -1);     if (B == 2)       x = 0;     break;   case 5:     x = (B == 2 ? -1 : 1);     if (B == 5)       x = 0;     break;   }   return x; } void copy(int N, int A[]) {   for (i = N; i &lt; 200; i++) {     A[i] = A[i - N];   } } int main() {   scanf("%d %d %d", &amp;N, &amp;NA, &amp;NB);   for (i = 0; i &lt; NA; i++) {     scanf("%d", &amp;A[i]);   }   copy(NA, A);   for (i = 0; i &lt; NB; i++) {     scanf("%d", &amp;B[i]);   }   copy(NB, B);   for (i = 0; i &lt; N; i++) {     Y += judge(A[i], B[i]);   }   if (Y &gt; 0) {     printf("A");   } else if (Y &lt; 0) {     printf("B");   } else     printf("draw");   return 0; }</pre>
这道题暂未补解析。
2. 简答题

谁考了第k名

在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。

时间限制:1000

内存限制:65536

输入

第一行有两个整数,分别是学生的人数n(1≤n≤100),和求第k名学生的k(1≤k≤n)。 其后有n行数据,每行包括一个学号(整数)和一个成绩(浮点数),中间用一个空格分隔。

输出

输出第k名学生的学号和成绩,中间用空格分隔。(注:请用%g输出成绩)

样例输入

5 3
90788001 67.8
90788002 90.3
90788003 61
90788004 68.4
90788005 73.9

样例输出

90788004 68.4
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;iostream&gt; #include &lt;stdio.h&gt; using namespace std; struct studen {   char name[20];   double num; }; int main() {   struct studen student[100];   struct studen t;   int n, k, i, j;   cin &gt;&gt; n &gt;&gt; k;   for (i = 0; i &lt; n; i++) {     cin &gt;&gt; student[i].name &gt;&gt; student[i].num;   }   for (i = 0; i &lt; n; i++)     for (j = 0; j &lt; n - i - 1; j++) {       if (student[j].num &lt; student[j + 1].num) {         t = student[j];         student[j] = student[j + 1];         student[j + 1] = t;       }     }   cout &lt;&lt; student[k - 1].name &lt;&lt; ' ' &lt;&lt; student[k - 1].num &lt;&lt; endl;   return 0; }</pre>
这道题暂未补解析。
3. 简答题

计算鞍点

给定一个5*5的矩阵,每行只有一个最大值,每列只有一个最小值,寻找这个矩阵的鞍点。 鞍点指的是矩阵中的一个元素,它是所在行的最大值,并且是所在列的最小值。 例如:在下面的例子中(第4行第1列的元素就是鞍点,值为8 )。

11 3 5 6 9

12 4 7 8 10

10 5 6 9 11

8  6 4 7 2

15 10 11 20 25

时间限制:1000

内存限制:65536

输入

输入包含一个5行5列的矩阵

输出

如果存在鞍点,输出鞍点所在的行、列及其值,如果不存在,输出"not found"

样例输入

11 3 5 6 9
12 4 7 8 10
10 5 6 9 11
8  6 4 7 2
15 10 11 20 25

样例输出

4 1 8
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;bits/stdc++.h&gt; using namespace std; int a[6][6]; int main() {   int i, j, x, z, y, flag1;   bool q;   for (i = 1; i &lt;= 5; i++)     for (j = 1; j &lt;= 5; j++)       cin &gt;&gt; a[i][j];   for (i = 1; i &lt;= 5; i++) {     x = 0;     flag1 = true;     for (j = 1; j &lt;= 5; j++)       if (a[i][j] &gt; x) {         x = a[i][j];         z = i;         y = j;       }     for (j = 1; j &lt;= 5; j++) {       if (a[j][y] &lt; x)         flag1 = false;     }     if (flag1 == true)     {       cout &lt;&lt; z &lt;&lt; " " &lt;&lt; y &lt;&lt; " " &lt;&lt; x;       return 0;     }   }   cout &lt;&lt; "not found";   return 0; }</pre>
这道题暂未补解析。
4. 简答题

合法C标识符

给定一个不包含空白符的字符串,请判断是否是C语言合法的标识符号(注:题目保证这些字符串一定不是C语言的保留字)。

C语言标识符要求:

1. 非保留字;

2. 只包含字母、数字及下划线(“_”)。

3. 不以数字开头。

时间限制:1000

内存限制:65536

输入

一行,包含一个字符串,字符串中不包含任何空白字符,且长度不大于20。

输出

一行,如果它是C语言的合法标识符,则输出yes,否则输出no。

样例输入

RKPEGX9R;TWyYcp

样例输出

no
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;iostream&gt; using namespace std; int main() {   string str;   cin &gt;&gt; str;   if (str[0] &gt;= '0' &amp;&amp; str[0] &lt;= '9') {     cout &lt;&lt; "no" &lt;&lt; endl;     return 0;   }   for (int i = 0; i &lt; str.length(); i++) {     if (!((str[i] &gt;= '0' &amp;&amp; str[i] &lt;= '9') ||           (str[i] &gt;= 'A' &amp;&amp; str[i] &lt;= 'Z') ||           (str[i] &gt;= 'a' &amp;&amp; str[i] &lt;= 'z') || str[i] == '_')) {       cout &lt;&lt; "no" &lt;&lt; endl;       return 0;     }   }   cout &lt;&lt; "yes" &lt;&lt; endl;   return 0; }</pre>
这道题暂未补解析。
5. 简答题

与指定数字相同的数的个数

输出一个整数序列中与指定数字相同的数的个数。

时间限制:1000

内存限制:65536

输入

输入包含三行: 第一行为N,表示整数序列的长度(N <= 100); 第二行为N个整数,整数之间以一个空格分开; 第三行包含一个整数,为指定的整数m。

输出

输出为N个数中与m相同的数的个数。

样例输入

3
2 3 2
2

样例输出

2
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;bits/stdc++.h&gt; using namespace std; int main() {   int n, a[105], m;   cin &gt;&gt; n;   for (int i = 0; i &lt; n; i++) {     cin &gt;&gt; a[i];   }   cin &gt;&gt; m;   int ans = 0;   for (int i = 0; i &lt; n; i++) {     if (a[i] == m) {       ans++;     }   }   cout &lt;&lt; ans;   return 0; }</pre>
这道题暂未补解析。