Beijing University of Aeronautics and Astronautics computer department postgraduate review computer real questions and answers --- first-level Construction Engineer real questions

Source: Internet
Author: User

Beijing University of Aeronautics and Astronautics computer department postgraduate review computer real questions and answers --- first-level Construction Engineer real questions

Question 1: factorial.

Enter a positive integer. when outputting, output the number itself, followed by a comma, and then output the factorial and equal signs of the numbers,

The calculation result of the factorial and determine whether the factorial and are equal to the original number. If Yes is equal, No is output. A positive integer

And all of their factorial and values will not exceed the int expression range.


Input Example 1:

145


Output Example 1:

145, 1! + 4! + 5! = 145

Yes


Input Example 2:

1400


Output Example 2:

1400,1! + 4! + 0! + 0! = 27

No

 

Question 2: wuziqi.

Enter a 19*19 matrix, which contains only numbers 0, 1, and 2, indicating the chess and Board status of the two players. 1 and 2 indicate the chess pieces of the two players, and 0 indicates space.

Determine whether the current state is successful (horizontal, vertical, or diagonal lines are connected to five same-color pawns ). Example

There are only five chess pieces in the same color in a row, and at most one person can win the game. If someone wins, add a colon to the output winner (1 or 2), and then output the winner

The coordinates of the first part of a five-beaded system. The smallest sequence number from top to bottom from left to right is the first, and the sequence number starts from 1. If no one wins, no is output.


Sample.

Reference answer (for personal writing only)

Question 1

1 #include "stdio.h"
 2 
 3
 4 //// shuaishuaizhang
 5
 6 int factorial (int n) {
 7 int sum = 1;
 8 for (int i = 2; i <= n; i ++) {
 9 sum = sum * i;
10}
11 return sum;
12}
13
14 void sum (int n) {
15
16
17 int a, b = n;
18 int s = 0;
19
20 int m = 10;
21 while (b / m! = 0) {
22 m = m * 10;
twenty three     }
24 m = m / 10;
25
26 while (m! = 0) {// Note that the positive sequence output is not reverse
27 a = b / m;
28 printf ("% d!", A);
29 b = b-a * m;
30 s = s + factorial (a);
31 m = m / 10;
32 if (m! = 0) {
33 printf ("+");
34} else {
35 printf ("=% d \ n", s);
36}
37}
38 if (n == s) {
39 printf ("Yes \ n");
40} else {
41 printf ("No \ n");
42}
43
44}
45
46 int main () {
47 int n;
48 freopen ("c: \\ input.txt", "r", stdin); // Input method
49 scanf ("% d", & n);
50 printf ("% d,", n);
51 sum (n);
52 return 0;
53}
 

The second question

// The input data does not meet the intent of the question, but the method is correct

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4
 5 #define M 19
 6 #define N 19
 7
 8 // shuaishuaizhang
 9 
10 void isWin (int a [M] [N], int m, int n) {
11 int t1, t2, t3, t4;
12 int i = 0, j = 0;
13 for (i = 0; i <m; i ++) {
14 t1 = 0, t2 = 0, t3 = 0, t4 = 0;
15 for (j = 0; j <n; j ++) {
16 if (j + 4 <19) {
17 t1 = a [i] [j] & a [i] [j + 1] & a [i] [j + 2] & a [i] [j + 3] & a [i] [j + 4] ;
18}
19 if (i + 4 <19 && j + 4 <19) {
20 t2 = a [i] [j] & a [i + 1] [j + 1] & a [i + 2] [j + 2] & a [i + 3] [j + 3] & a [i +4] [j + 4];
twenty one             }
22 if (i + 4 <19) {
23 t3 = a [i] [j] & a [i + 1] [j] & a [i + 2] [j] & a [i + 3] [j] & a [i + 4] [j] ;
twenty four             }
25 if (i + 4 <19 && j-4> = 0) {
26 t4 = a [i] [j] & a [i + 1] [j-1] & a [i + 2] [j-2] & a [i + 3] [j-3] & a [i +4] [j-4];
27}
28
29 if (t1! = 0 || t2! = 0 || t3! = 0 || t4! = 0) {
30 break;
31}
32}
33 if (t1! = 0 || t2! = 0 || t3! = 0 || t4! = 0) {
34 break;
35}
36}
37 if (t1! = 0) {
38 printf ("% d:% d,% d \ n", t1, i + 1, j + 1);
39}
40 else if (t2! = 0) {
41 printf ("% d:% d,% d \ n", t2, i + 1, j + 1);
42}
43 else if (t3! = 0) {
44 printf ("% d:% d,% d \ n", t3, i + 1, j + 1);
45}
46 else if (t4! = 0) {
47 printf ("% d:% d,% d \ n", t4, i + 1, j + 1);
48} else {
49 printf ("no \ n");
50}
51
52}
53
54 int main () {
55 srand (time (0));
56 int a [M] [N];
57 for (int i = 0; i <M; i ++) {
58 for (int j = 0; j <N; j ++) {
59 a [i] [j] = rand ()% 3;
60 printf ("% d", a [i] [j]);
61}
62 printf ("\ n");
63}
64 isWin (a, M, N);
65
66 return 0;
67}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.