First, PTA laboratory work (4 points) Topic 1:7-2 count the number of words in a line of text 1. PTA Submission List
2. Design ideas (pseudo-code or flowchart)
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
- (1) Part of the correct
- Resolution: On the second if judgment condition && | | Confused
(2) part of the correct
WORKAROUND: Because my code is the end of the return key, and the previous code also has a space, so I do not know how to determine which space is the end of, also asked the TA, the TA said I was behind or and the relationship is too confusing, so I gave up this practice
Error code:
#include<stdio.h>int main(){ char ch[1000]; int count=0,i=0,g=0; while((ch[g]=getchar())!=‘\n‘) g++;for(i=0;i<g;i++){ if((ch[i]<‘a‘||ch[i]>‘z‘)&&(ch[i]<‘A‘||ch[i]>‘Z‘)&&(ch[i]<‘0‘||ch[i]>‘9‘)){ if((i+1)!=g&&((ch[i-1]<=‘z‘)&&(ch[i-1]>=‘a‘)||(ch[i-1]<=‘Z‘)&&(ch[i-1]>=‘A‘))||(i+1)!=g&&((ch[i+1]<=‘z‘)&&(ch[i+1]>=‘a‘)||(ch[i+1]<=‘Z‘)&&(ch[i+1]>=‘A‘)))//if((ch[i-1]<=‘z‘)&&(ch[i-1]>=‘a‘)&&(ch[i+1]<=‘z‘)&&(ch[i+1]>=‘a‘)||(ch[i-1]<=‘Z‘)&&(ch[i+1]>=‘A‘)&&(ch[i-1]<=‘Z‘)&&(ch[i+1]>=‘A‘)) count++; } } printf("%d",count);
Topic 2:7-5 Statistics uppercase consonant letter 1. PTA Submission List
2. Design Ideas
定义数组op[80],循环变量i,辅音字母数量count,for i=0 to i=79 op[i]=输入 if op[i]不等于‘\n’ if op[i]不等于元音字母且为字母 count++; else break; end for; 输出count
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
- Error One: The final sentence condition is not designed at first, resulting in a program entering 80 numbers to output the result
- Error Two: No judgment is uppercase, the result is 5
- Error Three: The answer is 5, debug, count is not initialized to 0
Topic 3:7-3 Find the longest string 1. PTA Submission List
2. Design ideas (pseudo-code or flowchart)
定义整型变量字符串长度1count1字符串长度2count2,循环变量i,j,字符串数量n定义字符型变量 a[80],longest[80]输入n读入数组longestcount1=此时longes的长度for i=0 to i=n-1 读入数组a count2=a的长度 如果 count2大于count1 count1等于count2end forfor j=0 to a[j]=‘\0’ longest[j]等于a[j];end forlongest[j]=‘\0’输出 The longest is: 数组longest
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
- I put the output end flag ' \ ' to the wrong array position, should be longest[j], I assigned to longest[j+1] cause longest[j] no content;
Second, this week's topic set PTA Final ranking. (2 points)
Third, peer code peer review (1 points) 1. Mutual evaluation of students name: Wang Yuying 2. My code, peer-reviewed student code
-(1) The King's Code
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.
- Wang Ying's code idea is to define a two-character variable, constant loop assignment, and the value of the assignment is a front and back relationship, when the front is a space after the character is judged as a word,
- My code idea is to directly assigned all the characters into the array, but also to use the previous array as a space after a not method to determine the word
- The difference:
The difficulty of this problem lies in the treatment of the first word, in this respect, Wang Yuying is to add a space before the first word, I will judge it, if there is a space, the number of words variable count initialization 0, if not initialized to 1
- Advantage:
Wang Ying's code is relatively concise, the number of lines of code less
My code is clear, if the first word has a space before, then the King's code will be a bit redundant
- I prefer the king of the Night, because and other topics confused, resulting in the code there are some unnecessary statements, and Wang classmate's code is always very concise, since can achieve the same results, why not choose a more simple Method!
Iv. Summary of the study this week (3 points) 1. What have you learned? 1.1 How are pointer variables defined?
-
The general form of defining pointer variables is as follows:
Type name pointer variable name 1, pointer variable name 2, ... * pointer variable name n;
int *p; char *q; char *p,*q;
-
- Null pointer
The null pointer is a special pointer with a value of 0, and the C language uses the symbolic constant null (defined in stdio.h) to represent the null value and ensures that the value will not be the address of any variable. Null refers to any pointer type assignment is legal. A pointer variable with a NULL pointer value indicates that it does not point to anything that is meaningful at the moment.
1.2 pointer addition operation in which case, can the 2 pointer variables be added to each other?
- When pointer addition is applied to the address element to which it points, for example, when the input array
int *p,a[10];p=a;for(i=0;i<10;i++,p++)scanf("%d",p)
- Pointers can be subtracted, multiplied, divided, but not added: two pointer variables of the same type can be subtracted, and their meaning indicates how many elements are spaced between the memory locations pointed to by the two pointers
1.3 The pointer does not assign the initial value, direct use, what happens, please use DEVC verification, and show?
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? 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.
- The concept of pointers is still not very skilled ... , so not.
1.6 How to define a pointer variable to an array, and how to use a pointer variable to represent an array element?
int a[10];int *p;p=a;
At this point P is a pointer to array a
1.7 How do I define a character pointer to a string? Where is the initial position after the pointer points to the string?
char *p;char str[10] = "asdfghj";p = str;
-Initial position is str[0].
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?
-The string pointer takes only one memory unit that can hold the address, stores the address of the first character of the string, rather than putting the string into the character pointer variable, in short, the string pointer can point to an address that does not need to allocate memory
2. What is your content this week? 2.1 Class allocation and how to revise the wrong questions. 2.2 Others not? How are we going to solve
(1) for the concept of pointers or Mengmengdongdong
- Solution: Multi-brush problems, read more topics, accumulate reading volume, see more, long, will naturally.
3. Array on-Machine exam summary 3.1 The wrong question, please list?
- It's embarrassing, but it's all wrong.
3.2 Wrong question How to revise, why wrong?
- At the beginning of the time in a tangle for an hour, resulting in emotional tension, will not be the topic, but also usually accumulate enough, do not have many problems
6-1
I didn't understand how to get to the back of the front, then the tracking variables see 1 is from the first to the last, then 2 from the second to the first and then repeat the 1 step to the last, when the 1 became the penultimate
- 6-2
- I split the transpose and sort, and I found that the error occurred when I turned on the transpose
- (1) Transpose
My previous train of thought was established on 3 3, that is, thefirst is a[0][1] and a[1][0],a[0][2] and a[2][0] conversion, a total of two times, namely (line-1) times, followed by a[0][0] diagonal down, the internal 22 array, the conversion is a[1] [2] and a[2][1] conversion, a total of one, less than the last 1.
Problem: The number of loops has been mistaken, causing the transpose to be incomplete
- So I went online to check the transpose method.
Compared to my triple loop, the online approach is relatively simple
As follows:
void trans_array(int a[][10],int n){int k,g,temp; for(g=0;g<n;g++){ for(k=0;k<g;k++){ temp=a[g][k]; a[g][k]=a[k][g]; a[k][g]=temp; }} return a;
- Question: It is not clear that the number of array positions will change after the change.
- Resolution: So the observation variable found transpose when the number on the diagonal is not changed, that is K<g
- (2) Sort
- Problem: Reversed and error
- Resolution: If the condition is wrong, should be a[j][l]>a[j][l+1], continue
That's right
Other because of the data array also to do PTA, so has not been resolved, the planned term for this Friday ago.
C Language Blog Job--character array