First, the PTA Experimental work topic 1:7-6 fall into the number of traps 1. PTA Submission List
2. Design Ideas
Beginint 整型变量N,number提取每个位的数字,sum计算和,i,n,j输入Nfor(i 1 to 10000;i加一){sum=0; n=N;//引入n,来保留N的值计算number=N/10;if(number等于0)//位数为1则 sum=N*3+1否则{//位数不是1for(j 1 to 5;j加一){number=N%10;sum=sum+number; N=N/10;}sum=N*3+1}if(sum等于n)输出i:sum且跳出循环,结束程序否则输出i:sum并使N=sum}End
3. Problems encountered in commissioning process and PTA submission List status note
- Error code
- Correct code
See the PTA error message "normal range multi-digit, with 0", you know you can not use while (number! =0) to calculate sum
So it's changed to a for loop because the title is a number less than 30000, so it loops up to 5 times.
Topic 2:7-7 fat red envelopes 1. PTA Submission List
2. Design Ideas
Beginint 整型变量money,thousand,fifty,twenty,ten,five,two,one输入money计算thousand=money/100; money=money-thousand*100;计算fifty=money/50; money=money-fifty*50;计算 twenty=money/20; money=money-twenty*20;计算ten=money/10; money=money-ten*10;计算five=money/5; money=money-five*5;计算two=money/2; money=money-two*2;计算one=money;输出 100元:thousand张\n 50元:fifty张\n 20元:twenty张\n 10元:ten张\n 5元:five张\n 2元:two张\n 1元:one张End
3. Problems encountered in commissioning process and PTA submission List status note
- Error code
- Correct code
At first Test instructions did not understand, the use of multi-cycle structure, resulting in a lot of running out of a lot of results, the topic requires the least number of money, so with the expression can solve the problem.
The topic 3:7-8 judges a valid identifier of 1. PTA Submission List
2. Design Ideas
Beginint 整型变量num为运算次数,flag=1,count=0为判断条件,i,j,kchar 数组a[79],ch吸收输入num后的回车输入numch吸收输入num后的回车for(i 0 to num-1;i加一){ for(j 0 to 78;j加一){输入数组a[j]if(j等于回车)break跳出循环;}if(a[0]是数字)则flag为0for(k 1 to 78;k加一){if(a[k]是字母、数字、下划线)则count加一if(k等于j)则跳出循环}if(flag不为0且count等于k-1)输出Yes //等于k-1是因为最后的空格也使count加一if(flag等于0或者count不等于k-1)输出No使count,flag变为初值,进行下一次循环//count=0;flag=1}End
3. Problems encountered in commissioning process and PTA submission List status note
- Error code
Just started with the GetChar, but the idea of writing is not written, and then change with just learned one-dimensional array to write, is to count groups can hold multiple data.
Just learn the array to its application is not familiar with, just a little change
When you change to this, you feel like it, and look at the debug window. There is no reply to the initial value of the judging condition after a cycle.
- Correct code
At last, the place that affected me in this question.
1. After inputting the number of operations num to enter, but the array is character type, it will be absorbed by the array, with a lot of methods to think of using a getchar to absorb the return
2. The condition of the output yes,no also changed many times, one condition is not enough, then defines a new condition to satisfy
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?
General form of definition: type an array group name [array length];
Initialization general form: Type an array group name [array length]={initial value table}; if static stored array static is not initialized, the system automatically assigns 0 to all array elements, and if dynamic array static is not initialized, all array element values are indeterminate.
- 1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?
The array name is an address constant that holds the first address of the array memory space.
- 1.3 Why use arrays?
An array is the most basic constructed type, which is an ordered set of data of the same type. Using arrays in your program allows you to use the same array variable names for a group of variables of the same type, using subscripts to differentiate between them. Its advantages are simple expression, good readability, easy to use the loop structure.
- 1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo code display.
Selection method
Beginint 整型变量i,k为循环次数,index存放最小值所在的下标,change作为交换变量输入数组长度nint 数组a[n]for(i 0 to n-1;i加一 )输入数依次赋给 数组afor(k 0 to n-2;k加一 ){index放最小值下标k for(i k+1 to n-1;i加一)//在未排序的数中找到最小值与a[k]交换 if(a[i]<a[index])index等于1 a[k]与a[index]交换}依次输出数组aEnd
Bubbling method
Beginint 整型变量i,k为循环次数,change作为交换变量输入数组长度nint 数组a[n]for(i 0 to n-1;i加一 )输入数依次赋给 数组a for (i = 0; i < n-1; i++) {// n个数,n- 1轮冒泡,每一轮都将当前最大的数推到最后 for (j = 0; j < n-1 - i; j++) // n-1- i,意思是每当经过一轮冒泡后,就减少一次比较 if (a[j] > a[j+1])交换a[j],a[j+1] } 依次输出数组aEnd
Direct Insertion Method
Beginint 整型变量i,k,j为循环次数,change作为交换变量输入数组长度nint 数组a[n]for(i 0 to n-1;i加一 )输入数依次赋给 数组afor(i 1 to n-1;i加一){change=a[i]for(j 0 to i-1;j加一){ if(change小于a[i]){ for(k i-1 to j;k减一){ a[k+1],a[k]交换}a[j]=change;跳出循环}}}for(i 0 to n-1;i加一)输出a[i]End
- 1.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?
Definition form: Type an array group name [line length] [column length];
There are two forms of initialization:
1. Initial value of branch assignment
Type an array group name [line length] [column length]={{initial value table 0},...,{initial value table K}, ...} ;
If the initialization is only for partial elements, if it is a static array, the initial value of the remaining elements is 0, and if it is a dynamic array, the initial value of the remaining elements is indeterminate.
2. Sequential assignment of initial values
Type an array group name [array length]={initial value table}; The data of the initial value table is assigned to the element in sequence based on the order in which the array elements are stored in memory
To initialize only partial elements, pay attention to the order of the data in the initial table
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.
for(i 0 to 行长度-1) for(j 0 to 列长度-1) if(i小于等于j) a [i] [j] 和a [j] [i] 交换
主对角线 i==j上三角 i<=j下三角 i>=j副对角线 i+j==N-1(N为行列长度)
1.8 What is the general application of a two-dimensional array?
Primarily used to represent problems related to two-dimensional tables and matrices.
2. This week's content, you are not what?
- 1. When referencing an array using a function, it is unclear how to invoke the
- 2. There are several ways to sort, and the idea is not clear.
- 3. Array subscript starting from 0, or sometimes not aware
- 4.PTA of the eighth question played for a long time, the first met a lot of problems
5. The code to find the numbers is not exactly clear.
C Language Blog Job-data type