C Language Blog Job-data type

Source: Internet
Author: User
Tags array length

First, the PTA Experiment Assignment Topic 1: The number that falls into the trap 1. PTA Submission List

2. Design Ideas
    • The first step: Define the Shaping variable n,i the number of judgements, sum of the numbers, number,count the sum of the last time after storing the loop, a stores the initial n value
    • Step Two: Initialize I=1,count=1
    • Step three: Enter N, initialize a equals n
    • Fourth step: while (Count!=sum&&sum!=a) loop fifth to Nineth step
    • Fifth Step: Count=sum,sum=0
    • Sixth step: As long as n is not equal to 0, the seventh step of the loop calculates the sum of the figures.
    • Seventh step: number=n%10; Sum=sum+number; N=N/10;
    • Eighth step: sum=sum*3+1, Output I and Sum
    • Nineth Step: i++ is the number of times plus 1,n=sum
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
    • (1) Through the commissioning of the micro-disk found that the first entry is the number of traps into the trap, will enter two cycles, output two times the same number and then stop, but the title requirement is if the first time is the number of number traps, then output only once, I by defining a variable a, so that it equals the first n, Judging whether they are the same, the same exits
Topic 2: Location Code Input Method 1. PTA Submission List

2. Design Ideas
    • First step: Define the character variable Ch1,ch2,ch3,ch4,ch_height,ch_lower
    • Step Two: Enter CH1,CH2,CH3,CH4
    • Step three: High byte to Region code plus 160,ch_height= (ch1-' 0 ') *10+ch2-' 0 ' +160
    • Fourth step: Low byte is the bit code plus 160,ch_lower= (ch3-' 0 ') *10+ch4-' 0 ' +160;
    • Fifth step: Output Ch_height ch_lower
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
    • (1) At the beginning of the calculation, this is calculated

      Figure out is the wrong answer, because I entered the character type variable, direct and shape number calculation resulted in an error, workaround: Change the character type variable to the shaping variable and then calculate
Topic 3: Simple Calculator 1. PTA Submission List

2. Design Ideas
    • First step: Define a global variable result
    • Second step: Define the shape addition function, subtraction function, multiplication function, division function, parameters are double variable number
    • Step three: Define the character variant CH, define the Shaping variable Number,count, initialize the count to 0
    • Fourth Step: Enter Number and CH
    • Sixth step: Result=number
    • Seventh step: When CH is not an equal sign, enter the loop, cycle the first
    • Eighth step: What is the symbol of CH into what function, that is, 12 steps
    • Nineth Step: Otherwise count++, and exit the loop
    • Tenth Step: Input ch
    • 11th Step: If Count is not 0, the output Eooro, otherwise the value of the output result
    • 12th Step: Result=result (the symbol of the corresponding function, the addition function is +) number
3. Code


4. Problems encountered in commissioning process and PTA submission List status note
    • (1) At first do not know the judgment Ch is division sign, number is 0 o'clock or enter another symbol, let it finally output as error. Workaround: Define a count as the judgment flag, and when there is an error input, let count++, finally determine the value of count to select output
Second, this week's topic set PTA Final Ranking

Iii. Summary of this week's study 1. What have you learned? 1.1 How is a one-dimensional array defined and initialized?

The format of the definition is 类型名 数组名 [数组长度]; initialized to 类型名 数组名 [数组长度] = {初值表}; omit the array length when initializing each number in the array

1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?

A one-dimensional array in-memory structure is continuous, linear

The array name is a pointer that represents the address of the first element of the array

1.3 Why use arrays?

Can be a large number of consecutive storage, do not use a variable to hold a single data, reduce the amount of code, with the array name and subscript can uniquely determine the elements of the array, after using the array, you can determine the number of positions in the array before and after the situation, to complete some without the array to achieve or achieve a cumbersome function

1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo code display.

Bubbling method
Bubble sorting: 22 compares the keywords of the records to be sorted, and finds that the two records are exchanged in reverse order until there are no reversed records.
Design ideas

    • First step: Define the variable int a[10],i,j,k
    • Step two: for (i=0;i<10;i++) input data into the array sequentially
    • Step three: for (i=0;i<9;i++) loop Fourth
    • Fourth step: for (j=0;j<10-i;j++) loop
    • The Fifth step: if (a[j]>a[j+1]) then exchange these two numbers namely k=a[j];a[j]=a[j+1];a[j+1]=k;
    • Sixth step: for (i=0;i<10;i++) output A[10] in turn each number

Insert Sort:
Design ideas

    • First step: Starting with the first element, the element can be thought to have been sorted
    • Step two: for (j=i-1; j>=0 && t>a[j]; j--) takes the next element and scans the sequence of elements that have been sorted from backward forward
    • Step three: A[j+1]=a[j]; that is, if the element (sorted) is greater than the new element, move the element to the next position
    • Fourth step: Repeat step 3 until you find the sorted element is less than or equal to the position of the new element
    • Fifth step: Insert the new element into the next position a[j+1]=a[j];
    • Sixth step: Repeat step 2~5

Select Insert:
Design ideas

    • The first step is to assign the array, n to the number of lengths
    • Step two: for (k=0;k<n-1;k++) index=k; min subscript as K-cycle third step
    • Step three: for (i=k++;i<n;i++) loop Fourth
    • Fourth step: If A[i] is less than the minimum value, the minimum value is exchanged with the value of the subscript K
    • Fifth step: Output array
4.5 What is the binary search method? It differs from the order lookup method?

Binary search method is to find the middle position of the array number, determine whether it is to look for the number, not the words, greater than the number to find, then left to continue two points, less than the number to find, then to the right two points.
The binary lookup method is applied to the sorted array, the speed is fast, and the sequential lookup method is used to repeat the group, which is inefficient when the array is large, but is not required by the arrays themselves, and is suitable for short arrays

1.6 How are two-dimensional arrays defined and initialized?

The two-dimensional array is defined in the form类型名 数组名 [行长度][列长度]
Initialization format 类型名 数组名 [行长度][列长度] = { {初值表0}, ... ,{初值表k}, ...} If all rows are initialized, the row length can be ignored

1.7 How is the matrix transpose implemented? In the matrix: the relationship between the row label I of the lower triangle, the upper triangle and the symmetric matrix J? Please state.

The transpose matrix can be implemented by a bit of code

    int i,n,j;    scanf("%d",&n);    int a[n][n];     for(i=0;i<n;i++){        for(j=0;j<n;j++){            scanf("%d",&a[i][j]);        }    }    for(i=0;i<n;i++){        for(j=0;j<n;j++)        printf("%2d",a[j][i]);        printf("\n");    }    return 0;

Lower Triangle J

1.8 What is the general application of a two-dimensional array?

When the number in the array represents more than one meaning, such as when we want to represent different people's scores for different subjects, there are two variables, different people and different subjects, so to use two-dimensional matrices, or matrices, we need to use two-dimensional arrays

2. This week's content, you are not what?

For array arrangement of three kinds of arrangement is not special understanding, and then for the specific application of the two-dimensional array, to do the PTA found really difficult, for different symbols of the priority understanding is not enough, the test found that many of the basis is just understanding is not enough.

C Language Blog Job-data type

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.