First, the PTA laboratory work Title 1:7-2 count the number of words in a line of text
PTA Submission List
Design ideas
3. Code
4. Problems encountered in debugging process and PTA Submission List situation description.
The first time I thought the final period is not a word, and then find the right students with different groups of data to try to know the period is also counted words, and then a paragraph error, I will start the definition of the array length of a long point on the
Topic 2:7-6 Jack Cheng's Troubles 2
PTA Submission List
Design ideas
int n,i,j,flag=0;输入n的值char bra[n];输入数据i for 0 to n-1if 为左括号,变为字符0 j for 0 to n-1 if 为右括号,变为字符0,跳出循环endend大括号处理方法同上 i for 0 to n-1//遍历数组,若不全为0,则未完全匹配 if 不为0,flag=1 if flag=0 输出True else 输出false
3. Code
4. Problems encountered in commissioning process and PTA submission List status note
The beginning of my idea is to use a marker to meet the left parenthesis on the self-increment, encountered the right parenthesis on the self-reduction, and finally determine whether the mark is 0, and then found that this does not match correctly, and then looked at the classmate's thinking, redesigned a thought
Topic 3:7-10 positive integers a+b
PTA Submission List
Design ideas
char A[80],B[80];int i,j,flag1=0,flag2=0,x=0,y=0,k=0;输入加数和被加数历数A,B字符个数i,j i for i-1 to 0 if A[i]不为数字,flag=1;跳出循环 x=x+(A[i]-‘0‘)*pow(10,k++);//将字符型数字转为整型 if x不在1~1000内 flag1=1;//界定范围 k=0 B数组处理同上 if flag1=0且flag2=0 正常输出 else if flag1=1且flag2=0左边不正常输出 else if flag1=0且flag2=1右边不正常输出else全不正常输出
3. Code
4. Problems encountered in commissioning process and PTA submission List status note
At first did not see the number has a range, so do not give it to define the scope, and then use the critical conditions to find the problem, and carefully read the topic to suddenly realize
Second, this week's topic set PTA Final Ranking
Third, peer-to-peer evaluation of code pairs
1. Mutual evaluation of the names of students
Zhang Zhixin
2. My code, peer-to-peer code (the core code here is good, not necessarily all the code, the figure indicates whose code.) )
My Code:
Zhang Zhixin'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.
He was wrong about the problem, I changed it for him.
His idea is to give the first string to str2, write down his length, and then each line below the length of the string is compared to str2, if it is longer than str2, then the string is assigned to STR2
His idea is a bit like finding the maximum, the idea is very simple, is the trouble point
Iv. Summary of this week's study
1. What have you learned?
1.1 How pointer variables are defined (design code can be rendered with markdown code symbols)?
int *pchar *pfloat *pdouble *p
1.2 pointer addition operation in which case, can the 2 pointer variables be added to each other?
Array, such as int *p,a[10];p =a, at this point P can be added integer, p+1, is a[1] address,. Pointers can be subtracted, 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 that the two pointers point to
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.
void bubble(int *p,int n){ int i,j,t; for(i=1;i<n;i++) for(j=0;j<n-i;j++,p++) if(*p>*(p+1)) { t=*p; *p=*(p+1); *(p+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?
int a[10],*p;p=a;
p denotes a[0], (p+1) means a[1] etc.
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] = "afjkfdhsjk";p = str;
Initial position points to the first character of the string
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>#define MAXN 80char *strmcat( char *str1, char *str2 );int main(){ char s[MAXN], t[MAXN]; int m; gets(s); gets(t); strmcat(s,t); printf("%s\n",s); return 0;}char *strmcat( char *str1, char *str2){ while(*str1) str1++; while(*str2) { *str1=*str2; str1++; str2++; }}
You can manipulate the elements in an address directly
2. What is your content this week?
2.1 Class allocation and how to revise the wrong questions.
Splitting the decimal and integer part of the real number, assigning the pointer a null pointer, so you can't write in it.
2.2 Others not? How are we going to solve
PTA ID that problem has a test point do not understand
int n,i,j=0,k,z,sum=0,flag1=0,flag2=0,a[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; scanf("%d",&n); char Z,id[n*19],M[11]={‘1‘,‘0‘,‘x‘,‘9‘,‘8‘,‘7‘,‘6‘,‘5‘,‘4‘,‘3‘,‘2‘}; getchar(); for(i=1;i<=n;i++) { j=0; flag1=0; flag2=0; Z=0; z=0; sum=0; while((id[j]=getchar())!=‘\n‘) { if(id[j]<‘0‘||id[j]>‘9‘) flag2=1; j++; } Z=id[j-1]; if(flag2==0) { for(k=0;k<17;k++) sum=sum+a[k]*(id[k]-‘0‘); z=sum%11; } if((Z!=M[z])||flag2==1) { flag1=1; for(k=0;k<18;k++) printf("%c",id[k]); putchar(‘\n‘); } } if(flag1==0)printf("All passed"); return 0;
3. The test summary of the array on the machine
3.1 The wrong question, please list?
In addition to the IP address translation problem
3.2 Wrong question How to revise, why wrong?
Too many wrong questions, so give the link [https://pintia.cn/problem-sets/938706667891023872/problems]
C Language Blog Job--character array