First, the PTA laboratory work problem 1.6-7 use the function to output a specified range of 1. PTA Submission List
2. Design Ideas
3. Problems encountered in debugging process and PTA Submission List situation description.
In the beginning I realized all functions of the function, submitted to PTA but the display in the maximum range has been timed out, completely do not know where to optimize
I was thinking that the maximum range should mean all the numbers from 1 to 10000, and I think we should try to output all the numbers.
I found that all the numbers except 1 are even, which means that the odd number can be used to reduce the time complexity of my code by half.
Let me change my for loop execution statement from i++ to i+=2, and if I is odd, by i++ way to turn it into an even number, perfect solution, there may be other rules of the end of the law but too lazy to find
Topic 2.6-8 The number of Fibonacci in the specified range using the function Output 1. PTA Submission List
2 Design Ideas
- Define the variable i=1,a=1,b=1 in the FIB function
- If N==1 or n==2, return directly to 1
- When I is true, enter the while loop
- i++
- A=a+b;
- B=b+a;
- If i== (n+1)/2 enters the judgment statement
And then judge if N is an odd number, return a, or return B.
- In the PRINTFN function
- Defining the Shaping array res[100],j=0,flag=0
- If M>n let m and N values Exchange if (M > N) {
int z;
z = m;
m = n;
n = z;
}
- for (int i = 1; i<=100; i++)
- If FIB (i) >= m&&fib (i) <= n
- Let the value of fib (i) be assigned to Res[j], and J + +
- Flag=1
- for (int i = 0; i < J; i++)
- Value of output RES[I]
- If I is not equal to j-1 the output space
If flag==0, the output no Fibonacci number
3. Problems encountered in debugging process and PTA Submission List situation description.
The difficulty of this problem is how to make the last number does not output space, the others are relatively simple. I think of two methods, the first method with the array, each time to output the value of the array res[j], and then let I and J to judge, if I is not equal to j-1, then all output a space, that is, the output value and the output space two things separate judgment. The second method is to define a variable cnt=1 used to do the counter, before each output to determine the value of CNT, if cnt==1, the output of a single number, CNT for the other value of the output space + number, cnt++
Topic 3.7-1 Combinatorial number 1. PTA Submission List
2. Design Ideas
- In the main function, define the shaping variable M,n
- If m<=n, output result =%.0f ", fact (M, N)
- In the fact function, define the double type variable numberator=1,denominator=1
- for (int i = n; i >= n-m+1; i--)
Numberator = i;
for (int j = m; j >= 1; j--)
Denominator = j;
return numberator/denominator;
3. Problems encountered in debugging process and PTA Submission List situation description.
The problem is not as troublesome as the problem, and does not need to be counted as m! in the subject. N! and (N-M)! , high school, combined number formula equivalent to [M(m-1)... * (m-n+1)]/[n(n-1)... The following algorithm can be used to calculate the number of combinations
Second, the student Code Mutual Evaluation 1. Mutual Evaluation of photos
2. My Code, mutual evaluation of the student code
6-7 use the function to output the number of ends in a specified range
My Code
Wu Yue's Code
3. What is the difference between the student code and the classmate's? What are their strengths? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.
In Wu Yue code, in the Factorsum function, he uses the IF statement to separate the case of number==1, and then uses a for loop to determine the condition of the number>1. And my code is just using a do-while loop to get all the cases in, and my code is doing better than Wu Yue. And the May code at the end to determine whether sum is ==num, this is not necessary, because the main function of the IF statement is to determine whether the return value is equal to the original number of statements, there is no need to judge in the function. In the Factorsum function, I prefer my Code
PRINTFPN function, Wu Yue code is not full, do not comment
Third, this week's topic set PTA Final ranking.
Iv. Summary of the study this week? 1. What have you learned? 1.1C language those data types?
- Basic data types, such as: Integer, Long integer, short integer, unsigned integer, unsigned long, unsigned short, character, single-precision floating point, double-precision floating point.
1.2 Character type data need to be aware of the place?
- Each character type data occupies one byte in memory.
- The definitions and values of integer and char variables are interchangeable.
1.3 Self-increment decrement operator?
- n++ is equivalent to executing the statement first, executing the n+=1,++n at the end of the statement is equivalent to executing the n+=1 first, then executing the statement, n--,--n the same
1.4 Operator Precedence?
- Elementary Operators > Single-mesh Operators > Arithmetic operators > Shift operators > Relational operators > Bitwise logical operators > Logical operators > Three mesh Operators > Assignment operators > Comma operators
- The monocular operator, the assignment operator, the trinocular operator, and the assignment operation are combined right-to-left.
What expressions are in 1.5C languages? What do you do wrong in class, please analyze the reason here?
- An assignment expression, a logical expression, a conditional expression, a relational expression.
- No
2. This week's content, you are not what?
- It's not very good to meet some unfamiliar operators, it takes a lot of practice.
3. Circular structure Examination Summary 1. What is wrong and how to change it?
The last problem time is not enough, only to achieve the most basic function, but some special requirements have not been realized, feel their thinking is not sensitive enough, some ideas still appear too late
2. is the exam result satisfactory, how to improve?
Not too satisfied, more practice, look at other people's code, learn some other people's code a bit, and the flat commonly used to think with DEVC is very difficult to use, just start do not know how to debug, resulting in my code if the problem is directly with the brain analog code output and the calculation of the various variables, very waste of time, Only to the last question, began to learn how to use DEVC debugging, wasted a lot of time
C Language Blog Job--function