First, the PTA Experiment Assignment Topic 1: The structure array is sorted by the total score 1. PTA Submission List
2. Design Ideas
求出每名学生的总分定义i,j循环变量for i=0 to n for j=0 to 3 p[i].sum+=p[i].score[j]将三个成绩累加即为总分end总分从高到低排序定义i,j循环变量定义结构体中间变量tfor i=0 to 5 for j=0 to 5-i 冒泡排序从高到低end
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
Workaround: Define the intermediate variable as a struct variable, exchanging the contents of the structure as a whole
Topic 2: Rational number comparison 1. PTA Submission List
2. Design Ideas
struct y{ int mol; int den;}n,m; //定义表示分子分母的结构体 //并同时定义两个结构体变量m,n定义a,b,c,d存放原始值输入两个有理数两个有理数进行通分比较两分子大小 并利用a,b,c,d输出结果
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
The answer is wrong : the subject is not difficult, just use the two number-pass, then compare the molecular size is good. The error is that the value of the last output has been changed and the output error
Debugging process:
Workaround: Define four variables to put the original values, and finally use them to output.
Topic 3: Time conversion 1. PTA Submission List
2. Design Ideas
struct time{ int hh; int mm; int ss;} now,result; //定义表示时间分钟秒钟的结构体 //并同时定义一个现在时间的和一个结果时间结构体变量定义n为要加的秒数输入结构体变量now和n利用时间60进制来换算出结果时间(此处运算不太好表述) result.ss=(now.ss+n)%60;//根据各自与60的进制关系计算 result.mm=(now.mm+(now.ss+n)/60)%60; result.hh=now.hh+(now.mm+(now.ss+n)/60)/60;if result.hh等于24 令它等于0
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
- partially correct : The last second to 0 o'clock, the output is 24 points
Workaround: Add a conditional judgment
Second, this week's topic set PTA Final ranking.
Third, reading code integer decomposition into several items of the sum
This problem is a Wednesday on the machine of a topic, at that time looked at the topic has the idea, but has not been done. Back to the Internet after a search, found that the original can be used to solve the problem of the idea of recursion, is indeed a lot simpler.
From the above code it is not difficult to see that his recursive exit is cumulative sum equal to the input N. But I think the recursive feature is simple in form, but in fact the details are numerous. There is a lot of detail to note.
#include<stdio.h>int N;int s[31]; // 存放划分结果 int top = -1; // 数组指针 int count = 0; // 统计输出的次数 int sum = 0; // 拆分项累加和 void division (int i);int main (){ scanf ("%d", &N); division (1); return 0; }void division (int i) { if (sum == N) { count ++; printf("%d=", N); int k; for (k=0; k<top; k++) { printf("%d+", s[k]); } if (count%4 == 0 || s[top] == N) { printf("%d\n", s[top]); } else { printf("%d;", s[top]); } return; } // 输出部分 if (sum > N) { return; } for (int j=i; j<=N; j++) { s[++top] = j; sum += j; division (j); sum -= j; top --; } // 算法主体 }
Time Conversion
This is then code, her method is simple and clear, will all the time to change the number of seconds, and finally in the conversion back. Understanding the above is a lot better than my 60, and her final output is also used when the%02d to solve the problem of 0 points, do not like me to add an if judgment.
Iv. Summary of this week's study 1. Summarize this week learning content structure, common body, enumerate this structure data type characteristics
Structs are custom data types that combine different types of data into a single whole, which is more like an evolutionary version of an array, and the elements in the array must be of the same type.
struct student{ int num; char name; int grade;};
struct type declarations describe the organization of the structure and do not allocate memory.
A common body is to make several different types of variables that share a memory (covering each other)
union 共用体名{ 类型标识符 成员名; 类型标识符 成员名; .........};
Enumeration elements are treated as constants, specified by the programmer at the time of definition, and cannot be assigned a value.
Principle of recursive function
A recursive function is a function that calls itself directly or indirectly.
Cons: Fast memory consumption, inconvenient reading and maintenance, low efficiency
Pros: Concise, suitable for solving factorial, programming problems involving reverse order
Tail recursion: The simplest calling function, which does not require a return call, is equivalent to a loop.
Macro definition: Use the macro to define some symbolic variables to facilitate the programming of the program.
- Use:
Symbolic constants, such as PI, define the size of the array to increase the flexibility of the program
Simple function implementation
Bring some convenience to program writing
2. List some of the wrong questions this week.
- The cycle condition of this problem is wrong, resulting in the last number not added
- The second empty of the problem does not really, after listening to the teacher to understand why this definition.
C Language Tenth Blog assignment--structure