当前位置:网站首页>C language I blog assignment 03

C language I blog assignment 03

2020-11-07 22:16:40 Jun Feng

Which course does this assignment belong to https://edu.cnblogs.com/campus/zswxy/CST2020-2/
Where are the requirements for this assignment https://edu.cnblogs.com/campus/zswxy/CST2020-2/homework/11453
The goal of this assignment be familiar with for The use of recycling , Learn other people's excellent code , Improve yourself
Student number 20208988

1.PTA Experiment assignment (15 branch / topic )

1.1 Before finding a simple interleaved sequence N Xiang He
Description of the topic : Calculation sequence 1 - 1/4 + 1/7 - 1/10 + ... Before N Sum of items

1.1.1 Screenshot of experimental code

1.1.2 Data processing :

 Data expression : The integer variable is defined x,y, Floating point variables i,sum.
 Data processing : Using the expression sum=sum+y*(1/(3*i-2) and for loop 

1.1.3 PTA Submit list and description

Q1: At first, I didn't see the need to input the test case myself .
A1: I noticed later , After correction, the procedure is correct .

1.2 Before the sequence of fractions N Xiang He
Description of the topic : Calculation sequence 2/1+3/2+5/3+8/5+... Before N Sum of items .
1.2.1 Screenshot of experimental code

1.2.2 Data processing

 Data expression : Defines floating point variables x, y, i, n, b, a.
 Data processing : Using the expression  b = b + y / x and for loop .

1.2.3 PTA Submit list and description

Q1: Didn't deal with it in the beginning x,y Direct value of the incremental transformation assignment relationship , It took a lot of time .
A1: After many attempts , Think of giving another variable first y The value of is assigned to x And solved the problem .

1.3 Before the square root sequence N Xiang He
Description of the topic : Calculate the sequence of square roots √1+√2+√3+⋯ Before N Sum of items
1.3.1 Screenshot of experimental code

1.3.2 Data processing

 Data expression : The integer variable is defined x,i, Floating point variables sum.
 Data processing : Using the expression sum=sum+sqrt(i) and for loop .

1.3.3 PTA Submit list and description

Q1: Code speed is slow , And practice .
A1: The problem is not too difficult , Once in a while

2. Reading the code (-5——5 branch )

class Solution {
public:
    int minimumOperations(string leaves) {
        int n = leaves.size();
        vector<vector<int>> f(n, vector<int>(3));
        f[0][0] = (leaves[0] == 'y');
        f[0][1] = f[0][2] = f[1][2] = INT_MAX;
        for (int i = 1; i < n; ++i) {
            int isRed = (leaves[i] == 'r');
            int isYellow = (leaves[i] == 'y');
            f[i][0] = f[i - 1][0] + isYellow;
            f[i][1] = min(f[i - 1][0], f[i - 1][1]) + isRed;
            if (i >= 2) {
                f[i][2] = min(f[i - 1][1], f[i - 1][2]) + isYellow;
            }
        }
        return f[n - 1][2];
    }
}

Code functions : To achieve the least number of adjustments will be two colors of leaf classification adjustment completed .
Code benefits : Throughout mathematical thought , Digitizing specific issues , It's very logical ,
Greatly reduces the possibility of compiling code error , And will for Circulation and if To combine sentences with
Simplify code complexity , And use the first letter of color as the identification character in order to recognize .

3. Learning summary (15 branch )
3.1 Learning progress bar (5 branch )

Zhou / date The time spent this week Lines of code Brief introduction of the knowledge learned The confusing question at present
The first week 16 Hours 300 That's ok Have a general understanding of this major no
In the second week of 20 Hours 600 That's ok Learned how to ask questions no
The third week 24 Hours 1200 That's ok for The use of recycling no

3.2 Accumulate lines of code and blog words (5 branch )

3.3 Learn to understand (5 branch )
Please review your learning process this week , If you have new ideas or new ways , Please make a note in time .
This week I learned for loop , Simplify the complexity of the code , It improves the efficiency of function operation , I realized. c The practical function of language .
c Language learning , Only through continuous practice accumulation and independent development can we really learn knowledge .

版权声明
本文为[Jun Feng]所创,转载请带上原文链接,感谢