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

青少年软件编程(C语言三级)等级考试真题试卷(2021年6月) VIP

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

一、简答题

1. 简答题

数对

给定2到15个不同的正整数,你的任务是计算这些数里面有多少个数对满足:数对中一个数是另一个数的两倍。 比如给定1 4 3 2 9 7 18 22,得到的答案是3,因为2是1的两倍,4是2个两倍,18是9的两倍。

时间限制:1000

内存限制:65536

输入

一行,给出2到15个两两不同且小于100的正整数。最后用0表示输入结束。

输出

一个整数,即有多少个数对满足其中一个数是另一个数的两倍。

样例输入

1 4 3 2 9 7 18 22 0

样例输出

3
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;iostream&gt; using namespace std; int main() {   int c = 0, x = 0;   int a[15];   for (int i = 0; i &lt; 15; i++) {     cin &gt;&gt; a[i];     if (a[i] == 0)       break;     c++;   }   for (int i = 0; i &lt; c; i++) {     for (int j = 0; j &lt; c; j++) {       if ((a[i] / a[j] == 2) &amp;&amp; (a[i] % a[j] == 0) &amp;&amp; a[j] != 0) {         x++;       }     }   }   cout &lt;&lt; x; }</pre>
这道题暂未补解析。
2. 简答题

井和绳子

有A, B, C, D, E五家人共用一口井,已知井深不超过k米。A, B, C, D, E的绳长各不相同,而且厘米表示的绳长一定是整数。

从井口放下绳索正好达到水面时:

(a)需要A家的绳n1条接上B家的绳1条

(b)需要B家的绳n2条接上C家的绳1条

(c)需要C家的绳n3条接上D家的绳1条

(d)需要D家的绳n4条接上E家的绳1条

(e)需要E家的绳n5条接上A家的绳1条

问井深和各家绳长。

时间限制:1000

内存限制:65536

输入

输入只有1行。包括空格分开的6个整数。 第一个整数k(1 <= k <= 20),代表井的最大深度(单位:米)。 接下来是5个正整数n1, n2, n3, n4, n5。这五个整数的含义见上面的题目描述。

输出

输出只有1行。 如果找到了可行解,就输出6个整数,用空格分开,分别代表井的深度和A, B, C, D, E的绳长(单位都是厘米)。 如果有多组可行解,输出井的深度最小的那组解。 如果不存在可行解,就输出一行: not found

样例输入

10 2 3 4 5 6

样例输出

721 265 191 148 129 76
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;iostream&gt; using namespace std; int main() {   int n[6], l, a, b, c, d, e, len;   cin &gt;&gt; l;   l *= 100;   for (int i = 1; i &lt;= 5; i++)     cin &gt;&gt; n[i];   int flag = 0;   for (len = 1; len &lt;= l; len++) {     for (a = 1; a &lt;= len; a++) {       b = len - n[1] * a;       c = len - n[2] * b;       d = len - n[3] * c;       e = len - n[4] * d;       if (a == b || a == c || a == d || a == e || b == c || b == d || b == e ||           c == d || c == e || d == e || a &lt;= 0 || b &lt;= 0 || c &lt;= 0 || d &lt;= 0 ||           e &lt;= 0)         continue;       if (e * n[5] + a == len) {         printf("%d %d %d %d %d %d\n", len, a, b, c, d, e);         return 0;       }     }   }   printf("not found");   return 0; }</pre>
这道题暂未补解析。
3. 简答题

爬楼

已知楼梯的数量,可以每次走2级或者3级,求不同的走法数

例如:楼梯一共有7级,一共3种方法:2 2 3或者 2 3 2 或者 3 2 2。

时间限制:1000

内存限制:65536

输入

输入包含若干行,每行包含一个正整数N,代表楼梯级数,1 <= N <= 50。 最后一行为0,表示测试结束。

输出

不同的走法数,每一行输入对应一行输出

样例输入

7
0

样例输出

3
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;iostream&gt; using namespace std; #define maxn 55 long long dp[maxn]; void init() {   dp[1] = 0, dp[2] = 1, dp[3] = 1, dp[4] = 1;   for (int i = 5; i &lt;= maxn; i++)     dp[i] = dp[i - 3] + dp[i - 2]; } int main() {   init();   int n;   while (cin &gt;&gt; n) {     if (n == 0) {       return 0;     }     cout &lt;&lt; dp[n] &lt;&lt; endl;   }   return 0; }</pre>
这道题暂未补解析。
4. 简答题

表达式求值

输入一个布尔表达式,请你输出它的真假值。

比如:( V | V ) & F & ( F | V )

V表示true,F表示false,&表示与,|表示或,!表示非。

上式的结果是F

时间限制:1000

内存限制:65536

输入

输入包含多行,每行一个布尔表达式,表达式中可以有空格,总长度不超过1000

输出

对每行输入,如果表达式为真,输出"V",否则出来"F"

样例输入

( V | V ) & F & ( F| V)
!V | V & V & !F & (F | V ) & (!F | F | !V & V)
(F&F|V|!V&!F&!(F|F&V))

样例输出

F
V
V
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;algorithm&gt; #include &lt;cmath&gt; #include &lt;cstring&gt; #include &lt;iomanip&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;vector&gt; using namespace std; char s[1005]; stack&lt;bool&gt; B; stack&lt;char&gt; C; int main() {   while (cin.getline(s, 1000, '\n')) {     int len = strlen(s);     while (!B.empty())       B.pop();     while (!C.empty())       C.pop();     for (int i = 0; i &lt; len; ++i) {       if (s[i] == ' ')         continue;       if (s[i] == 'V') {         bool tmp = true;         while (!C.empty() &amp;&amp; C.top() == '!') {           C.pop();           tmp = !tmp;         }         B.push(tmp);       } else if (s[i] == 'F') {         bool tmp = false;         while (!C.empty() &amp;&amp; C.top() == '!') {           C.pop();           tmp = !tmp;         }         B.push(tmp);       } else if (s[i] == '(' || s[i] == '!') {         C.push(s[i]);       } else if (s[i] == ')') {         while (C.top() != '(') {           char op = C.top();           C.pop();           bool tmp1 = B.top();           B.pop();           bool tmp2 = B.top();           B.pop();           if (op == '&amp;')             B.push(tmp2 &amp;&amp; tmp1);           else if (op == '|')             B.push(tmp2 || tmp1);         }         C.pop();         while (!C.empty() &amp;&amp; C.top() == '!') {           bool tmp = B.top();           B.pop();           B.push(!tmp);           C.pop();         }       } else if (s[i] == '&amp;') {         while (!C.empty() &amp;&amp; C.top() == '&amp;') {           C.pop();           bool tmp1 = B.top();           B.pop();           bool tmp2 = B.top();           B.pop();           B.push(tmp1 &amp;&amp; tmp2);         }         C.push(s[i]);       } else if (s[i] == '|') {         while (!C.empty() &amp;&amp; (C.top() == '|' || C.top() == '&amp;')) {           bool tmp1 = B.top();           B.pop();           bool tmp2 = B.top();           B.pop();           char op = C.top();           C.pop();           if (op == '&amp;')             B.push(tmp1 &amp;&amp; tmp2);           else if (op == '|')             B.push(tmp1 || tmp2);         }         C.push(s[i]);       }     }     while (!C.empty()) {       bool tmp1 = B.top();       B.pop();       bool tmp2 = B.top();       B.pop();       char op = C.top();       C.pop();       if (op == '&amp;')         B.push(tmp1 &amp;&amp; tmp2);       else if (op == '|')         B.push(tmp1 || tmp2);     }     if (B.top())       cout &lt;&lt; "V" &lt;&lt; endl;     else       cout &lt;&lt; "F" &lt;&lt; endl;   }   return 0; }</pre>
这道题暂未补解析。
5. 简答题

数列

用以下方式构造数列: 数列的第一个和第二个数都为1,接下来每个数都等于前面2个数之和。

给出一个正整数a,要求数列中第a个数对1000取模的结果是多少。

时间限制:1000

内存限制:65536

输入

第1行是测试数据的组数n,后面跟着n行输入。每组测试数据占1行,包括一个正整数a(1 <= a <= 1000000)。

输出

n行,每行输出对应一个输入。输出应是一个正整数,为数列中第a个数对1000取模得到的结果。

样例输入

4
5
2
19
1

样例输出

5
1
181
1
查看答案与解析
答案:<pre class="brush:cpp;toolbar:false">#include &lt;iostream&gt; using namespace std; int main() {   int n = 0;   cin &gt;&gt; n;   int a[n];   for (int i = 0; i &lt; n; i++) {     int a, f0 = 1, f1 = 1, f2;     cin &gt;&gt; a;     if (a == 1 || a == 2) {       cout &lt;&lt; 1 &lt;&lt; endl;     } else {       for (int j = 3; j &lt;= a; j++) {         f2 = (f0 + f1) % 1000;         f0 = f1;         f1 = f2;       }       f0 = 1;       f1 = 1;       cout &lt;&lt; f2 &lt;&lt; endl;     }   } }</pre>
这道题暂未补解析。