Blue Bridge Cup fill in the blanks set 1

Source: Internet
Author: User

1, least common multiple

Finding the least common multiple of two numbers is a very common operation. For example, the minimum male of 3 and 5 is 15. The least common multiple of 6 and 8 is 24.
The following code asks for the least common multiple of the given two positive integers. Please fill in the missing code to make the program run as efficiently as possible.

Fill in the blanks answer (only the answer in the blanks, not including the surface) into the candidate folder corresponding to the "answer. txt" in the title.

 1  int  F ( int  A, int   b)  2  3  int   I;  4  for  (i= A;; ___)  5  {  if  (I%b==0 ) return   I;  7   8  }
Reference answer: i+== i + A; Note: I+ + can get the correct results, but does not match test instructions (efficient operation), do not give points. 
View Code

2. Number of combinations

Choose 2 from 4 people to participate in the event, a total of 6 kinds of election method.

How many options do you have to choose m individuals to participate in an activity from n individuals? The following function implements this function.

Please carefully analyze the code and fill in the missing part (underlined section).

Note: Please fill in the blanks answer (only the answer, not including the surface) in the candidate folder corresponding to the "answer. txt".
Write directly on the surface and not score.

1 //n elements, whichever is the M element, how many kinds of2 intFintNintm)3 {4     if(m>n)return 0;5     if(m==0) _______________;6 7     returnF (n1, M-1) + _____________;8}

Reference Answer:

Empty 1:h (space+1, x1) (6 min) empty 2:x-I (3 min) (char) ((int) x-i) Of course it is possible to have a lot of writing, substituting into the source program, see the results of the operation. 
View Code

3. Pyramids

The goal of the following code is to output a pyramid of uppercase letters.
Where space represents the left blank length of the bottom of the pyramid, and X represents the center letter of the bottom of the pyramid.
For example: space=0, x= ' C ', then output:
A
ABA
ABCBA
Again such as: space=2,x= ' E ', then the output:
A
ABA
ABCBA
Abcdcba
Abcdedcba

Please analyze the logic of this section of code and fill in the missing parts.
Fill in the blanks answer (only the answer in the blanks, not including the surface) into the candidate folder corresponding to the "answer. txt" in the title.

1 voidHintSpaceCharx)2 {3     inti;4     if(x<'A'|| X>'Z')return;5     _______________;6      for(i=0; i<space; i++) printf (" ");7      for(i=0; i<x-'A'; i++) printf ("%c",'A'+i);8      for(i=0; i<=x-'A'; i++) printf ("%c",______);9printf"\ n");Ten}

Reference Answer:

Empty 1:h (space+1, x1) (6 min) empty 2:x-I (3 min) (char) ((int) x-i) Of course it's possible.
View Code

4. Self-guarding number

If the end of the square of a natural number is still the natural number itself, it is called a self-holding number.
For example:
5 x 5 = 25
x 76 = 5776
625 x 625 = 390625

The purpose of the code below is to find out all the self-guarding numbers within 20 million.

Note that the square of 20 million has exceeded the maximum range of integer representations, so the program uses an ingenious scheme.
If we look closely at the computational process of multiplication, we will find a link that actually contributes to the mantissa of the product, thus eliminating the need to really calculate the entire product.

Please analyze the code and fill in the missing parts.

Note: Please fill in the blanks answer (only the answer, not including the surface) in the candidate folder corresponding to the "answer. txt".
Write directly on the surface and not score.

1 voidZishou ()2 {3     intN;4      for(n=1; n< -* +* +; n++)5     {6         intN2 =N; 7         intm =0;8          for(;;)9         {Ten             if(n2==0)  One             { Aprintf"%d\n", n); -                  Break; -             } the              -             intK = n2%Ten;//starting at the end, remove each digit of the multiplier -M + = k * N;//Cumulative Product -             if(_________________) Break; +m = m/Ten;//to the bottom of the cumulative product -N2 = _______________;  +         } A     } at}
Fill in the   blanks 1:  ten ! = K or  :ten  m%-k== 0   Fill in the  Blanks 2:ten
View Code

5. Winning calculation

The rules of a lottery are: each participant writes a 8-digit number on the paper. Finally, a 8-digit number is randomly generated by the method of the prize draw. The maximum number of consecutive digits written by the participant is the same as in the draw number, which is called a number.
For example: The number of small Zhang is: 12345678, and the lottery number is: 42347856. It is said that there are 3 numbers in the sheet, because the longest of the same continuous bit is: "234". If Xiao Zhang is writing: 87654321, then he has only one number.
The following code returns a few numbers, depending on the parameters passed in. Where: a denotes the number to be evaluated and B represents the number produced by the number. Please fill in the missing code.

Fill in the blanks answer (only the answer in the blanks, not including the surface) into the candidate folder corresponding to the "answer. txt" in the title.

1 intGintAintb)2 {3     Charsa[]="00000000";4     Charsb[]="00000000";5     intn =0;6     inti,j;7 8sprintf (SA,"%8d", a);9sprintf (SB,"%8d", b);Ten      for(i=0; i<8; i++) One     { A          for(j=1; j<=8-I.; J + +) -         { -             Chart = ________; theSA[I+J] =0; -             if(Strstr (SB, sa+i)) -             { -                 if(j>N) _________; +             } -SA[I+J] =T; +         } A     } at  -     returnN; -}
  Reference Answer:  empty 1:sa[i+j]    (4 min)  = J      (5 min)  Note the equivalence of pointers to array forms.   * (SA+I+J) is the same
View Code

6, open Square

If there is no calculator, how do we ask for the square root of 2?
You can guess a number first, say 1.5, and then divide 2 by this number. If we guessed right, the result of division must be the same as the number we guessed. The more accurate we guess, the closer the result of division is to the number of guesses.
According to this principle, as long as we take the guess number and try to divide the feedback number of the median as a new guess, definitely closer to the answer! This method of calculation is called "iterative method".

The following code simulates the process of using a manual method to find the square root of 2. Please fill in the missing code.

    Double 2 ;     Double 0 ;     double B = n;      while (Fabs (A-B) >1e-)    {        = (a+b)/2;         = __________;    }    printf ("%f\n", a);
N/A
View Code

7 . Suppose that A,b,c is a 3-unequal integer. The following code takes out the values centered in them and records them in M. The swap () function can exchange the values of two variables. Please complete the code.

    if (a>b) Swap (&a, &b);     if (b>c) Swap (&b, &c);    ______________________;     int m = b;
if (a>b) Swap (&a, &B) Note: A>b can also be written as b<Aswap (&a, &b) as: Swap (&b, &a) is right.
View Code

8, given a string, such as "AABBBCDDDDKKKMMMMAAKKKK" we want to remove the continuous repetition of the letter, the string: "Abcdkmak", the following code to implement the function, please perfect it.

1     Char* p ="AABBBCDDDDKKKMMMMAAKKKK";2     Charbuf[ -];3 4     Char* Q =p;5     intI=0;6      for(;*q;)7     {8         if(___________| | *q! = * (q1))9         {Tenbuf[i++] = *Q; One         } Aq++; -     } -Buf[i] =' /'; the  -printf"%s\n", buf);
reference Answer: Q= =P Here I feel the fillin I ==0 is also reasonable, to ensure that the first time to execute if statements on the line
View Code

Blue Bridge Cup fill in the blanks 1

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.