Typical Programming Problems

Source: Internet
Author: User

[Procedure 1]
Question: classical question: there is a rabbit. From the first 3rd months after birth, a rabbit is born every month. After the third month, a rabbit is born every month. If the Rabbit does not die, what is the total number of rabbits per month?
1. program analysis: the rabbit rule is a sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21 ....

[Procedure 2]
Question: determine the number of prime numbers between-and output all prime numbers.
1. Program Analysis: Method for Determining prime numbers: Remove 2 to SQRT (This number) with a single number. If the number can be divisible,
It indicates that this number is not a prime number, and vice versa.

[Procedure 3]
Question: print out all the "Daffodils". The so-called "Daffodils" refers to a three-digit number, each of which is equal to the number itself. For example, 153 is a "Daffodils" because 153 = the power of 1 + the power of 5 + the power of 3.
1. program analysis: The for loop is used to control the number of 100-999. Each number is used to calculate a single digit, ten digits, and hundreds of digits.

[Procedure 4]
Question: decompose a positive integer into a prime factor. For example, enter 90 and print 90 = 2*3*3*5.
Program Analysis: to break down the prime factor of N, first find a minimum prime number k, and then follow the steps below:
(1) If the prime number is equal to N, it indicates that the process of decomposing the prime factor is over. Print it out.
(2) If n <> K, but N can be divisible by K, the value of K should be printed, and N is divided by the quotient of K, as the new positive integer you n, repeat the first step.
(3) If n cannot be divisible by K, k + 1 is used as the value of K and the first step is repeated.

[Procedure 5]
Question: Use nested conditional operators to complete this question: Students with scores> = 90 are represented by a, students with scores between 60 and 89 are represented by B, and students with scores below 60 are represented by C.
1. program analysis: (A> B )? A: B is a basic example of conditional operators.

[Procedure 6]
Question: enter two positive integers m and n to obtain the maximum common approx. And the minimum public multiple.
1. Program Analysis: using rolling division.

[Procedure 7]
Question: enter a line of characters to calculate the numbers of English letters, spaces, numbers, and other characters.
1. Program Analysis: using the while statement, the condition is that the input character is not '/N '.

[Procedure 8]
Question: calculate the value of S = a + AA + AAA + AAAA + AA... A, where A is a number. For example, 2 + 22 + 222 + 2222 + 22222 (a total of 5 numbers are added at this time), and the addition of several numbers is controlled by the keyboard.
1. program analysis: the key is to calculate the value of each item.

[Procedure 9]
Question: If a number is equal to the sum of its factors, this number is called "complete number ". For example, 6 = 1 + 2 + 3. Program to find all the completion numbers within 1000.

[Procedure 10]
Question: How many meters does a ball fall from the height of 100 meters to half of the original height after each arrival? How high is the rebound of 10th times?

[Procedure 11]
Question: How many three numbers can be composed of 1, 2, 3, and 4 numbers that are different from each other and have no repeated numbers? What is it?
1. Program Analysis: It can be filled in hundreds of digits, ten digits, and one digit is 1, 2, 3, and 4. Make up all the sorting before dropping the sorting that does not meet the conditions.

[Procedure 12]
Question: The bonus paid by an enterprise is based on the profit. If the profit (I) is less than or equal to 0.1 million yuan, the bonus can be raised by 10%; if the profit is higher than 0.1 million yuan, if the profit is lower than 0.2 million yuan, the portion lower than 0.1 million yuan will be charged by 10%, and the portion higher than 0.1 million yuan, 7.5% for Coco; 0.2 million for a part higher than 0.4 million yuan between 0.2 million and 5%; 0.4 million for a part higher than 0.6 million yuan between 0.4 million and 3%, or for a part higher than yuan; between 0.6 million and 1 million, if the price is higher than 0.6 million yuan, the price can be increased to 1.5%. If the price is higher than 1 million yuan, the price of more than 1 million yuan is increased by 1%, and the current month's profit is input from the keyboard, how many bonuses should be paid?
1. Program Analysis: Use the number axis to divide and locate. Note that you need to define the bonus type as a growth integer.

[Procedure 13]
Question: an integer. After 100 is added, it is a full number of workers, and 168 is a full number of workers. What is this number?
1. program Analysis: if the number is less than 0.1 million, add 100 to the number before the start, and then add 268 to the number before the start. If the result after the start meets the following conditions, it is the result. See the specific analysis:

[Procedure 14]
Question: enter a day of a year to determine the day of the year?
1. program Analysis: Taking June 1, March 5 as an example, we should add up the previous two months, and then add 5 days, that is, the day of the current year. In special cases, an additional day is required when the input month is greater than 3 in a leap year.

[Procedure 15]
Question: input three integers x, y, and z. Please output these three numbers from small to large.
1. program Analysis: we try to put the smallest number on X and compare X with y first. If x> Y, the values of X and Y are exchanged, then compare X with Z. If x> Z, the value of X is exchanged with Z to minimize X.

[Procedure 16]
Question: 9*9 tips.
1. Program Analysis: For branch and column consideration, there are 9 rows and 9 columns, I control row and J control column.

[Procedure 17]
Question: monkeys eat peaches. On the first day, the monkeys picked a few peaches and immediately ate half of them. They were not addicted, and they ate another one. On the morning of the next day, they ate half of the remaining peaches, I ate another one. In the future, I eat the remaining half of the previous day every morning. When you want to eat again in the morning of the seventh day, there is only one peach left. Calculate the total number of extracted items on the first day.
1. program analysis: the reverse thinking method is used to infer from the back.

[Procedure 18]
Question: two table tennis teams have three members each. Team A is A, B, and C, and Team B is X, Y, and Z. The game list has been determined by lottery. Someone asked the players about the game list. A said that he is not in comparison with X, C said that he is not in comparison with X and Z. please compile a program to find a list of three-team players.
1. Program Analysis: Method for Determining prime numbers: Remove 2 to SQRT (This number) with a single number. If it can be divisible, it indicates that this number is not a prime number, and vice versa.

[Procedure 19]
Question: print the case (diamond)
*
***
******
********
******
***
*
1. Program Analysis: first, divide the graph into two parts. The first four rows have a rule, and the last three rows have a rule. Using a dual for loop, the first layer controls the row and the second layer controls the column.

[Procedure 20]
Question: There is a fractional sequence: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13... find the sum of the first 20 items of this series.
1. Program Analysis: grasp the variation rules between numerator and denominator.

[Procedure 21]
Question: 1 + 2! + 3! +... + 20! And
1. Program Analysis: This program only converts accumulation into multiplication.

[Procedure 22]
Question: Use the recursive method to calculate 5 !.
1. Program Analysis: recursive formula: fn = fn_1 * 4!

[Procedure 23]
Question: How old are five people sitting together? He said he is two years older than 4th. Asked about the age of 4th People, he said he was two years older than 3rd people. Ask the third person, and say that the person is two years older than 2nd. Ask 2nd people, saying they are two years older than the first. Finally, I asked the first person that he was 10 years old. How old is the fifth person?
1. Program Analysis: Using recursive methods, recursion is divided into two stages: push-back and recursion. To know the age of the fifth person, you need to know the age of the fourth person, and so on, and push it back to the first person (10 years old.

[Procedure 24]
Question: give a positive integer of no more than five digits. Requirement: 1. How many digits is it? 2. Print the numbers in reverse order.

[Procedure 25]
Question: a 5-digit query to determine whether it is a return number. That is to say, 12321 is the number of replies, with the same number of digits and tens of thousands of digits.

Procedure 26]
Question: Enter the first letter of the day of the week to determine the day of the week. If the first letter is the same, continue to judge the second letter.
1. Program Analysis: it is better to use the case statement. If the first letter is the same, the case statement or if statement is used to determine the second letter.

Procedure 27]
Question: Calculate the prime number within 100

[Program 28]
Question: Sorting 10 numbers
1. program Analysis: You can use the selection method, that is, from the last nine comparison processes, select a minimum to exchange with the first element, and so on, that is, compare the second element with the last eight, and exchange.

[Procedure 29]
Question: Calculate the sum of the diagonal elements of a 3*3 matrix
1. program analysis: the dual for loop is used to control the input two-dimensional array, and then a [I] [I] is accumulated and output.

[Procedure 30]
Question: There is a sorted array. Enter a number to insert it into the array according to the original rule.
1. Program Analysis: first, determine whether the number is greater than the last number, and then consider the number inserted in the middle. After the element is inserted, the number is shifted to the next position.

[Procedure 31]
Question: output an array in reverse order.
1. Program Analysis: Use the first and last exchanges.

[Program 32]
Question: Take an integer a from 4 ~ 7 digits.
Program Analysis: consider the following:
(1) first shift A to four places.
(2) Set a four-bit low to 1, and the rest to 0. Available ~ (~ 0 <4)
(3) perform & operations on the above two.

[Procedure 33]
Question: print out the Yang Hui triangle (10 rows are required, for example)
1. program analysis:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

[Procedure 34]
Question: input 3 numbers A, B, C, and output in order of size.
1. Program Analysis: Use the pointer method.

[Procedure 35]
Question: Input array. The largest element is exchanged with the first element, the smallest element is exchanged with the last element, and the output array is used.

[Procedure 36]
Question: There are n integers, so that the previous numbers are shifted to the next M positions, and the last M number is the first M number.

[Procedure 37]
Question: There are n people in a circle with sequential troubleshooting. When the first person reports the number (from 1 to 3), the person who reports the number 3 leaves the circle and asks the last person who left the number.

[Procedure 38]
Question: Write a function, calculate the length of a string, input a string in the main function, and output its length.

Program 39]
Question: compile a function. When n is an even number, call the function to calculate 1/2 + 1/4 +... + 1/n. When n is an odd number, call the function 1/1 + 1/3 +... + 1/N (using pointer functions)

[Procedure 40]
Question: String sorting.

[Procedure 41]
Question: there are a bunch of peaches on the beach, and five monkeys can score points. The first monkey divided the pile of peach creden into five portions, one more. The monkey threw the other one into the sea and took one. The second monkey divides the remaining peaches into five equal portions and adds one more portion. It also throws one more portion into the sea and takes one portion, the third, fourth, and fifth monkeys did this. How many peaches did they have on the beach?

[Procedure 42]
Question: 809 *?? = 800 *?? + 9 *?? + 1 where ?? Two digits, 8 *?? The result is two digits, 9 *?? The result is 3 digits. Please ?? Represents two digits, and 809 *?? .

[Procedure 43]
Question: calculate the number of odd numbers that can be composed of 0 to 7.

[Procedure 44]
Question: an even number can always represent the sum of two prime numbers.

[Procedure 45]
Question: judge whether a prime number can be divisible by a few 9

[Procedure 46]
Question: Two string connection programs

[Procedure 47]
Question: Read the integer of 7 Numbers (1-50). Each time a value is read, the program prints * of the number of values *.

[Procedure 48]
Question: A company uses a public phone to transmit data. The data is a four-digit integer and encrypted during the transmission process. The encryption rules are as follows: add 5 to each number, then, replace the number with the remainder divided by 10, and then exchange the first and fourth digits, and the second and third digits.

[Procedure 49]
Question: calculate the number of times a string neutron string appears

[Program 50]
Question: five students, each having scores for three courses, input the above data from the keyboard (including student ID, name, and score for the three courses) to calculate the average score, the original data and the calculated average score are stored in the disk file "stud.

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.