C Language Blog Job--character array

Source: Internet
Author: User

One, the PTA experiment homework problem one. Find the longest string 1. PTA Submission List

2. Design Ideas
    • (1) Define n as the number of strings to be entered below, define I as a loop control variable to traverse each string, and define the input string as the largest array of op-retained strings,
      Defines the maximum number of characters for a string of Max and assigns an initial value of 0, defines the variable s to traverse the OP to the most, and defines the input of the variable J for each string.
    • (2) Input n
    • (3) for (i=0;i<n;i++) {let J equals 0;
    • (4) Enter each string with GetChar and record the number of characters with J
    • (4) If max<j, let max=j; and the OP at this time will assign op to the most end
    • (5) Output The longest is:%s\n,most
3. Code

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

Two times the wrong answer seems to be a parenthesis without an alignment missing a parenthesis.

Topic Two. Jack Cheng's Troubles 21. PTA Submission List

2. Design Ideas

The design idea of this problem is to divide the brackets into pieces of each one to judge.

    • (1) Define two variables C1 and C2 respectively for each block start and result and give the initial value 0, define n is used to record the number of parentheses, define J to traverse each block, flag1=0 used to record each block end of the character array subscript, Flag2 to determine whether each block satisfies the mathematical parentheses use method , the definition array op is used to hold the parentheses content
    • (2) Enter N, use GetChar to eliminate the effect of the newline character, and enter the parenthesis string with GetChar.
    • (3) while (1) {flag1=0,flag2=0; c2=c;
    • (4) for (j=c;j<n;j++) {when op[j] equals} or) Flag1=1 flag this pit stop
      if (flag1==1&& (op[j]== ' | | op[j]== ' {')) {C=j;break;end
    • (5) if (j==n) c=n; This step is for the last quick judgment to determine the end of the subscript
    • (6) for (j=c2;j< (c2+c)/2;j++)
      Because the first half is all left parenthesis, the second half is the closing parenthesis and the parentheses are paired
      if (op[j]== ' (') {
      if (op[(c2+c)-j-1]== ') ') continue;
      else{flag2=1; break;}
      }
      else if (op[j]== ' {') {
      if (op[(c2+c)/2]== '} ') continue;
      else{flag2=1; break;}
      }
      else {flag2=1; break;}
    • (7) If Flag2==1 or c==n ends the loop end
    • (8) If n%2! =0 Output False
    • (9) Output true if flag2=0
      -(10) Reverse output false

      3. Code

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

I didn't understand it at first. The correct use of brackets is that (()) () This type of two blocks above is the wrong way to use is also very distressed why they have been submitting errors, and later asked the teacher found errors.

Topic three. Archaic typesetting 1. PTA Submission List

2. Design Ideas

3. Code

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

The difficulty lies in examining, the idea is relatively simple.

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

Zhong Wenjie

2. My Code, mutual evaluation of the student code

He
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 called the library function inside the original existing function, I did not, his more simple and convenient, but need to remember, I am more complex. I prefer his concise style.

Iv. Study Summary of the Week 1. What did you learn? 1.1 How pointer variables are defined (design code can be rendered with markdown code symbols)?

int a; int *i=&a;

1.2 pointer addition operation in which case, can the 2 pointer variables be added to each other?

Using the pointer plus a constant, two pointers cannot be added as the hotel number 503 plus 607 is meaningless.

1.3 The pointer does not assign the initial value, direct use, what happens, please use DEVC verification, and show?

Program crashes

1.4 Lessons about separating the integer and fractional parts of a floating-point number, use DEVC to verify the implementation, and show it in this map, and also indicate which is the pointer variable to do the function parameter, and how the function argument should be represented. What is the use of pointer variables for function parameters? ‘


Pointer variables do function parameters:
How the function arguments should be represented:
It is possible to manipulate variables of the main function to implement multiple worthwhile returns.

1.5 Please change the bubble sort function of the textbook into a pointer variable to do the formal parameter format, and write the code at the bottom, pay attention to the markdown syntax rendering
void bubble(int *a,int n){    int i,j,t;      for(i=0;i<n-1;i++){          for(j=0;j<n-i-1;j++){                 if(*(a+j)>*(a+j+1)){                  t=*(a+j);                  *(a+j)=*(a+j+1);                  *(a+j+1)=t;                }           }    
1.6 How to define a pointer variable to an array, and how to use a pointer variable to represent an array element?

Let the pointer point to the first address of the array, which is the array name or element of the array.
(1) Manipulate the pointer as an array
(2) Add the pointer to the number I so that the pointer iterates through the array each element address.

1.7 How do I define a character pointer to a string? Where is the initial position after the pointer points to the string?
在c语言中定义一个指针 char *p;char str[10] = "afjkfdhsjk";p = str;

Pointer p points to the first address of the string str

1.8 Use a character pointer to manipulate strings, such as design functions, to implement string joins, and show the code in this map. What are the advantages of the method that indicates the pointer represents a character?
#include<stdio.h>#include<string.h>void connect(char*op,char*cpunt);int main(){   int k=0,i=0,j=0;    char op[20];    char count[20];    gets(op);    gets(count);    connect(op,count);    printf("%s",op);    return 0;}void connect(char*op,char*count) {    strcat(op,count); }

Can point to an address that does not need to allocate memory, the communication protocol used more than the general point of message content.

2. This week's content, you are not what? 2.1 Class allocation and how to revise the wrong questions.

Pointer and array second question empty, should be filled out is the address is not the number so to write is P+n
Select the seventh item in the pointer job selection C, *p is the value is not the address.

2.2 Others not? How are we going to solve

The pointer thought is not skillful, does many questions, solves more.

3. Array on-Machine exam summary 3.1 The wrong question, please list?

The problem is not wrong is the matrix which problem with the choice of sorting method to do relatively low

3.2 Wrong question How to revise, why wrong?

No

C Language Blog Job--character array

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.