C Language Blog Job--one or two-dimensional array

Source: Internet
Author: User
Tags array length

One, the PTA experiment Homework topic one. Simplified insertion sort 1. PTA Submission List

2. Design ideas (insert by dichotomy)
    • (1) Define a number N array width and enter this number, define two data to retain the left and right end of the number of left=0;right=n-1, and their middle number
    • (2) define an array n[80].
    • (3) Define a loop variable i,for (i=0;i<n;i++) {Number of input array n[i];
    • (4) Define the number of inserts as a, enter this number
    • (5) while (Left<=right)
    • (6) {mid= (left+right)/2;
    • (7)
      if (A>n[mid]) left=mid+1;
      else if (A<n[mid]) right=mid-1;}
    • (8) then start refactoring array for (right=n;right>=left;right--)
      {n[right]=n[right-1];}
    • (9) Finally, a is inserted into the n[i]=a;
    • (10) Output result for (i=0;i<n;i++) printf ("%d", A[i])
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

I used in the PTA is the first use of sequential sorting method. Later know the dichotomy of efficiency changes because you do not see the format of the problem in the wrong way the other is generally correct.

Topic two. Find a saddle point 1. PTA Submission List

2. Design Ideas
    • (1) Define n as the scale of the square and enter N, define the loop variable I,J to control the input and output, define D to preserve the number of each position in the square, define m for the row comparison definition falg=0 used to determine whether the output.
    • (2) Define a two-dimensional array c[n][n].
    • (3) for (i=0;i<n;i++) {
      for (j=0;j<n;j++) {input c[i][a]}}
    • (4) for (i=0;i<n;i++) {
      for (j=0;j<n;j++) {The value of C[i][j] is assigned to D;
    • (5) for (m=0;m<n;m++) {
      The d is then compared to all the elements of the row if D is larger than one of the rows, and jumps out of the layer loop. }
    • (6) If m==n for (g=0;g<n;g++) {then compares the element to this column and then compares D to all elements of that column if D is less than a number in this column jumps out of the loop;) when g==n outputs I J and let Flag=1}}
    • (7) If the flag=0 output is none.

      3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

The rows and columns are soft and messy, and then the comments are not so messy. Overall, it's not difficult.

Topic three Monkey Choice King 1. PTA Submission List

2. Design ideas (a general look at the topic, in the beginning there is a thought is to let the data has been increased not always repeat although not meet the test instructions but the result must be right. It can be manipulated to keep the data going again, but I think it will be more troublesome.
    • (1) Enter n for the number of monkeys, define a=0 as the number of reports, define count to record the number of not 0, define s used to save the monkey number;
    • (2) define an array length of d[n+1] because there are no No. 0 monkeys, so this operation will simply discard D[0], and then iterate over the array to assign the initial value all the output is 1.
    • (3) for (i=1;i<n+1;i++) {count=0;
    • (4) If d[i]=0 skips this cycle
    • (5) Otherwise let a++, and let D[i]=a if D[i] take the remainder 3 o'clock let d[i]=0;
    • (6) for (i=1;i<n+1;i++) when d[i]!=0 if d[i]!=0,count+1 and let S equals i} if count=1 jumps out of the loop and outputs s}
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

The question is to cross the already 7 monkeys the second time off more difficult to operate the other is not a problem

Second, this week's topic set PTA Submission List and the final ranking. PTA Rankings

Third, peer code peer review 1. Peer evaluation of the names of students

Zhang Zhixin

2. My Code, mutual evaluation of the student code

Zhang Zhixin:
I:

3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.

He may not have seen the subject. His approach is to redefine an array, though convenient, but a waste of space. Not very agreeable. My code is more complex but it saves space but should be able to optimize the number of shifts and N/2 comparison to see how the output.

Iv. Study Summary of the Week 1. What did you learn? How do I store strings in 1.1. C?

1, in the C language to store a string, there are generally two methods, one is a character pointer, one is to use a character array.

1.2. What is the end flag of a string and why do I want to end it?

0, because each character in the character array is random if there is no end flag to determine where the read ends.

1.3. What are the different methods for string input?

Three kinds of GetChar gets scanf

1.4. How do numeric characters turn into integers and write pseudo-code?

Char C
int a;a=c-' 0 '. Prinft ("%d,a);

1.5.16 binary, binary string how do I turn 10 binary? Write pseudo-code?

a=0;
for (i=0;c[i];i++) {
A=a*2 (16) +c[i]-' 0 '}

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

Learn many different sorts of search methods.

3. Midterm Summary 3.1 Why do you think you didn't do well?

Without a good review, the knowledge is not very strong. There is a lack of exam skills. It's just a very messy writing.

3.2 List the wrong questions.

Choice 1 does not understand 8421 yards of this thing is 10 binary.
Output results The second question has not been learned recursion, thought is from inside function to outer function actual opposite.
The first question number in the blanks is wrong.
The first question of programming forgets how random numbers are generated

include <stdlib.h>include <stdio.h>include <time.h>           //使用当前时钟做种子void main( void ){int i;srand( time( NULL ) );          //初始化随机数 rand() 就是随机数

C Language Blog Job--one or two-dimensional array

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.