C/C ++ true questions and question solutions
1. Number of couponsSome people are superstitious about numbers. For example, a number with "4" is considered unlucky to have a homophone with "death. Although these statements are purely nonsense, they sometimes have to cater to the needs of the masses. The coupon number for a lottery activity is 5 digits (10000-99999). do not include a "4" number. The organizer should calculate the number, if no duplicate number exists for any two coupons, the maximum number of coupons can be issued. Please submit this number (an integer) without any additional content or descriptive text.
2. Galaxy bombsIn the vast space of Galaxy X, a number of X-star man-made "bombs" floated as signs of the universe. Each bomb can be set to how many days later to explode. For example, if the Alpha bomb was placed on February 15, January 1, 2015 for a period of 15 days, it exploded on February 15, January 16, 2015. There is a beta bomb, which will be placed in December November 9, 2014 and is scheduled to be 1000 days. Please calculate the exact date of its explosion. Enter the date in the format of yyyy-mm-dd, that is, four-digit year, two-digit month, two-digit date. For example, please strictly follow the format in. Other text or symbols are not allowed.
3. sanyang xiangruiObserve the following addition formula:
The same Chinese Character represents the same number, and different Chinese characters represent different numbers. Please fill in the four digits (the only answer) represented by "sanyang xiangrui" and do not fill in any additional content.
4. Output in the gridThe StringInGrid function prints the specified string in a grid of the specified size. The string must be centered horizontally and vertically. If the string is too long, it is truncated. If it cannot be centered exactly, you can make it a little left or a little above. The following program implements this logic. Enter the code that is missing in the dashes. # Include # Include Void StringInGrid (int width, int height, const char * s) {int I, k; char buf [1000]; strcpy (buf, s); if (strlen (s)> width-2) buf [width-2] = 0; printf ("+"); for (I = 0; I Printf ("+ \ n"); for (k = 1; k <(height-1)/2; k ++) {printf ("| "); for (I = 0; I Printf ("| \ n");} printf ("|"); printf ("% * s ",_____________________________________________); // fill in printf ("| \ n"); for (k = (height-1)/2 + 1; k Printf ("|"); for (I = 0; I Printf ("| \ n");} printf ("+"); for (I = 0; I Printf ("+ \ n") ;}int main () {StringInGrid (20, 6, "abcd1234"); return 0 ;}for the data in the question, it should be output: Note: enter only the missing content. Do not write any existing code or descriptive text on the Question surface.
5. Nine array scoresThe nine numbers 1/3, 3... 9 constitute a score with a value of exactly. How to group the score? The following program implements this function. Enter the code missing in the dash section. # Include Void test (int x []) {int a = x [0] * 1000 + x [1] * 100 + x [2] * 10 + x [3]; int B = x [4] * 10000 + x [5] * 1000 + x [6] * 100 + x [7] * 10 + x [8]; if (a * 3 = B) printf ("% d/% d \ n", a, B);} void f (int x [], int k) {int I, t; if (k> = 9) {test (x); return ;}for (I = k; I <9; I ++) {t = x [k]; x [k] = x [I]; x [I] = t;} f (x, k + 1 ); _________________________________________________ //} int main () {int x [] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; f (x, 0); re Turn 0;} Note: enter only the missing content. Do not write any existing code or descriptive text on the Question surface.
6. addition, variable MultiplicationWe all know that: 1 + 2 + 3 +... + 49 = 1225 now you are required to convert two non-adjacent plus signs into a multiplication sign, so that the result is 2015 for example: 1 + 2 + 3 +... + 10*11 + 12 +... + 27*28 + 29 +... + 49 = 2015 is the answer that meets the requirements. Please look for another possible answer and submit the number on the left of the multiplication number at the top (for example, submit 10 ). Note: You must submit an integer and do not enter any additional content.
7. Card TypeJames was hijacked to gambling city X and forced to play cards with three others. A pair of playing cards (52 cards in total, excluding the trump card size) were evenly distributed to four people, each with 13 cards. At this time, James suddenly encountered a problem in his mind: if he did not consider the color, he would only consider the number of points and the order of his cards, how many initial card combinations do you have? Enter this integer, and do not enter any additional content or instructions.
8. moving distanceThe buildings in the residential area of Planet X are all the same and arranged in a matrix style. The number of the building is 1, 2, 3... when a row is full, the number is arranged from the adjacent building in the next row to the opposite direction. For example, when the cell line number is 6, the first situation is as follows: 1 2 3 4 5 6 12 11 10 9 8 7 13 14 15 ..... our problem is: we have learned the numbers m and n of the two buildings. We need to find the shortest moving distance between them (not moving in the diagonal line). The input is a three integer w m n, separated by spaces, in the range of 1 to 10000, w is the layout width, m, and n are the building numbers to be calculated. An integer must be output, indicating the shortest distance between the two floors of m n. For example, if user input: 6 8 2, the program should output: 4. For example, if user input: 4 7 20, the program should output: 5 Resource conventions: peak memory consumption <256 m cpu consumption <1000 ms, please output strictly as required, do not print it like: "Please input.... All codes are stored in the same source file. After debugging is successful, copy and submit the source code. Note: The main function must return 0. Note: Only the ansi c/ansi c ++ standard is used. Do not call special functions that depend on the compiling environment or operating system. Note: All dependent functions must be explicitly included in the source file # include Common header files cannot be omitted through project settings. When submitting, select the expected compiler type.
9. Base diceIn old age, the gambling atm is infatuated with the base dice, that is, putting the dice on the top of the other. It cannot be twisted and twisted to form a square column. After a long period of observation, atm has discovered the mystery of the stable dice: some numbers are mutually exclusive! Let's regulate the dice first: the opposite of 1 is 4, the opposite of 2 is 5, and the opposite of 3 is 6. Assuming that m groups are mutually exclusive, and the two digits in each group are closely tied together, the dice cannot be stabilized. The atm wants to calculate how many different possible base dice methods are available. The two dice have the same method. If and only when the two dice have the same orientation as the number corresponding to the height. Because the number of solutions may be too large, please output the result of MOD 10 ^ 9 + 7. Don't underestimate the number of dice in the atm ~ "Input format" two integers n m n in the first line indicate the number of dice in the next m row. Each row has two integers a B, indicating that numbers a and B cannot be closely linked. "Output format" is a row of numbers, indicating the result of the 10 ^ 9 + 7 answer model. Sample input 2 1 2 sample output 544 data range for 30%: n <= 5 for 60% of data: n <= 100 for 100% of the data: 0 <n <= 10 ^ 9, m <= 36 Resource conventions: peak memory consumption <256 m cpu consumption <2000 ms, please output strictly as required, do not print it like: "Please input.... All codes are stored in the same source file. After debugging is successful, copy and submit the source code. Note: The main function must return 0. Note: Only the ansi c/ansi c ++ standard is used. Do not call special functions that depend on the compiling environment or operating system. Note: All dependent functions must be explicitly included in the source file # include Common header files cannot be omitted through project settings. When submitting, select the expected compiler type.
10. Tree of LifeIn forest X, God created the Tree of Life. Each node (a leaf is also called a node) of each tree is labeled with an integer representing the harmonious value of this vertex. God wants to select a non-empty node set S in this tree, so that any two vertices a and B in S have a point column {a, v1, v2 ,..., vk, B} makes each vertex in this vertex column an element in S, and an edge is connected between two adjacent vertices in the sequence. On this premise, God wants to make the sum of the integers corresponding to the points in S as big as possible. The greatest sum is God's score on the Tree of Life. Through the atm's efforts, he has learned the integers God has given to each node on each tree. However, because atm is not good at computing, he does not know how to calculate the score effectively. He needs you to write a program for him to calculate the score of a tree. The input format is an integer n in the first line, indicating that the tree has n nodes. N integers in the second row, indicating the scores of each node in turn. In the next n-1 row, there are two integers u and v in each row, indicating that there is an edge from u to v. Because this is a tree, there is no ring. "Output format" outputs a number for a row, indicating the score given to the tree by God. Sample input 5 1-2-3 4 4 2 3 1 1 2 2 5 sample output 8 data range for 30% of the data, n <= 10 for 100% of data, 0 <n <= 10 ^ 5. The absolute value of each node's score cannot exceed 10 ^ 6. Resource Conventions: peak memory consumption <256 m cpu consumption <3000 ms, please output strictly as required. Do not print anything similar to "Please input. All codes are stored in the same source file. After debugging is successful, copy and submit the source code. Note: The main function must return 0. Note: Only the ansi c/ansi c ++ standard is used. Do not call special functions that depend on the compiling environment or operating system. Note: All dependent functions must be explicitly included in the source file # include Common header files cannot be omitted through project settings. When submitting, select the expected compiler type.