C Language Structure work

Source: Internet
Author: User

Tag: is the array C language struct data type one otherwise different class Getch

First, PTA laboratory work title 1:6-3 the structure array to find the specified number of people 1. PTA Submission List

2. Design Ideas
定义一个结构体指针*pfor i=0 to i=7     如果std+i的编号与输入的编号一样     将std+i的地址传给pend for返回p
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.
    • No errors
Topic 2:7-2 Time Conversion 1. PTA Submission List

2. Design Ideas
定义结构体数组Time,其内容包括时,分,秒定义一个字符ch,增加的秒数n,结构体变量time输入time和n如果time中的秒数加上n大于等于60   time.s加上n后再减去60  time的分钟数加上1否则   time.s加上n如果time中的分钟数大于等于60    time.m减去60   time的小时数加上1如果time的小时数等于24    time.h减去24输出结果
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.
    • The number of seconds plus n is greater than or equal to 60 minus 60, but the first time I did forget to add n is not greater than or equal to 60 of the case, this time is to add n but not minus 60
Title 3:7-6 the entry and display of the Address Book 1. PTA Submission List

2. Design Ideas
定义一个结构体变量person,内容为姓名 生日 性别 固话 手机定义整型变量n,k,num,输入n,定义结构体数组friends[n]for  i=0 to i=n-1            输入结构体数组的所有变量end  i输入kfor  j=1  to  j=k       输入num       如果num小于n且大于等于0    输出friends[num]的姓名 固话 手机 性别 生日       否则  输出Not Foundend  j
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.
    • My definition of gender is a character, after entering the gender, there should be a getchar () to absorb space, otherwise the space will be absorbed by the gender
    • In the bottom j of the loop, in the case of NUM is greater than or equal to 0 and less than n output, but I do not notice, write less than equal to N, in the DEVC by the wrong point of PTA debugging also Yes, I tried many times after I had to look at their code, this only to find my mistake
Second, this week's topic set PTA Final ranking.

Third, read code 1: a bunch of one
    • Title Description: Enter the first line to give positive even n (<=50), that is, the number of students in the class. Thereafter n rows, the gender of each student is given in the order of rank from highest to lowest (0 for girls, 1 for boys) and for names (non-empty strings with no more than 8 English letters), separated by 1 spaces. This ensures that the male and female ratio of this class is 1:1, and there is no juxtaposition.
      Each row outputs the names of a group of two students, separated by 1 spaces. Top ranked students in the former, ranked lower students in the post. The output order of the group is ranked from highest to lowest in the previous student's rank.
    • This code uses structs to represent students, the following loop outputs the first half of the students, and then starts looking for students to pair with, and the function of array B is to determine if the corresponding student has exited.
    • First of all, the students ' information includes the gender of the name, and the structure is more convenient and concise; This code first outputs the first half of the students, and then cleverly uses array B to avoid the students who have already been exported.
2: Fibonacci sequence
    • The function is to output the Fibonacci sequence.
    • By recursive function, the calculation of Fibonacci sequence is simple, the code is easy to understand, but too many recursion times can cause stack overflow.
Iv. Study Summary of the Week 1. Summarize what you learned this week. 1, the structure, the common body, enumerates this constructs the data type characteristic.
    • Structs and arrays are structured data types, and arrays are different, and structs can handle different types of data. Structure can also have the structure type, the type of the common body of data.
    • A common body is a constructed type of multivariate shared storage space that allows several different variables to share the same storage space. Differences between common and structural bodies:
      1. Each member of a struct is used to represent a property of a specific transaction, and a shared body member can represent multiple attributes (the same storage space can store different types of data).
      2. The total size of the structure is equal to the overall length of each member, and the shared space equals the space occupied by the largest member.
      3. The common body cannot be assigned an initial value.
    • An enumeration type is a value of a variable that can be listed all, and the value of a variable is defined in the definition after an enumeration variable is defined. The difference between it and the struct, the common body is that the enumeration element is a constant and can only be assigned at the definition stage.

      2. Principle of recursive function
    • Recursion is the conversion of a big problem that cannot or cannot be solved into one or a few small problems, and then the smaller problems are further decomposed into smaller ones, until every small problem can be solved directly.
    • The essence of recursive algorithm is to transform the problem into a sub-problem of the same kind of problem with scale reduction. The function (or procedure) is then called recursively to represent the solution to the problem.
    • The recursive algorithm solves the problem characteristic:
      (1) Recursion is the invocation of itself in a procedure or function.
      (2) When using a recursive strategy, there must be a definite recursive end condition called a recursive exit.
      (3) Recursive algorithm is usually very concise, but the recursive algorithm is less efficient in solving problems. Therefore, the recursive algorithm is generally not advocated for the design of the program.
      (4) in the process of recursive invocation, the system opens up a stack for each layer's return point, local quantity and so on to store. Too many recursion times can cause stack overflow and so on. Therefore, the recursive algorithm is generally not advocated for the design of the program.

      2. List some of the wrong questions this week.
    • 1.
      This question is actually very simple, but I did not look carefully, the addition as a multiplication, so think to 0 when the return 0, multiplied by 0 equals 0; in fact, this is an addition, the answer should be 10.
    • 2.
      I did not pay attention to the question, thinking that the last 7 when the output is gone, in fact, every time the calculation will be output once

C Language Structure work

Related Article

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.