Computer Department of Beihang University second-round examination of the real problem and answer---2014

Source: Internet
Author: User

The first question, the order multiplier. Enter a positive integer, output, first output the number itself, followed by a comma, and then output the number of the numbers of the factorial and, equals, factorial and the results of the calculation, and determine whether the factorial and is equal to the original number, if the equal output Yes, otherwise output No. The title indicates that the positive integers entered and the factorial and none of them will exceed the representation range of the int type. Input sample 1:145 Output sample 1:145,1!+4!+5!=145 Yes Input sample 2:1400 output Example 2:1400,1!+4!+0!+0!=27 No the second question, Gobang. Enter a 19*19 matrix that contains only the numbers 0, 1, 2, which represent the gobang of the two people, 1, 2, respectively, representing the two, and 0 for the space. It is required to determine whether someone wins in the current state (horizontal, vertical, or diagonal direction is connected to a 5-color piece). The input sample ensures that there are at most 5 consecutive colored pieces on each line and that at most only 1 people win. If someone wins, the output winner (1 or 2) adds a colon, and then outputs the coordinates of the first piece of the winning five-alignment, from the top to the bottom, from left to right, with the smallest ordinal number starting with 1. If no one wins, output No. Reference answer (I write, only for communication) The first question # include "stdio.h" int factorial (int n) {int sum=1;for (int i=2; i<=n; i++) {sum = Sum*i;} return sum;} void sum (int n) {int A, b = n;int s = 0;int m=10;//Note is the positive ordinal output, not the reverse output, so you want to start from the front except while (b/m! = 0) {m = m*10;} m = M/10;while (M!=0) {a = b/m;printf ("%d!", a), b = B-a*m;s = s + factorial (a); m = m/10;if (M! = 0) {printf ("+");} else{printf ("=%d\n", s);}} if (n = = s) {printf ("yes\n");} else{printf ("no\n");}} int main () {int N;freopen ("C:\\input.txt", "R", stdin), scanf ("%d", &n);p rintf ("%d,", n); sum (n); return 0;} The second question//with the generated array, and test instructions is not 100% in line with, but find a way no problem # include #include #include #define M 19#define n 19void iswin (int a[m][n],int m,int n) {int t1,t2,t3,t4;int i=0,j=0;for (i=0; i =0) {t4 = A[i][j] & A[i+1][j-1] & A[i+2][j-2] & A[i+3][j-3] & a[i+4][j-4];} if (T1!=0 | | T2! = 0 | | t3!=0 | | T4! = 0) {break;}} if (T1!=0 | | T2! = 0 | | t3!=0 | | T4! = 0) {break;}} if (T1!=0) {printf ("%d:%d,%d\n", t1,i+1,j+1);} else if (T2!=0) {printf ("%d:%d,%d\n", t2,i+1,j+1);} else if (T3!=0) {printf ("%d:%d,%d\n", t3,i+1,j+1);} else if (T4!=0) {printf ("%d:%d,%d\n", t4,i+1,j+1);} else{printf ("no\n");}} int main () {Srand (time (0)), int a[m][n];for (int i=0; I University of Aeronautics and Astronautics computer department second-round exam on the real question and answer---
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.