Tag: Dex sum failed XOR or line break expression. com paint multiple times
First, the PTA experimental work Title 1:7-4 print diamond pattern 1. PTA Submission List
2. Design Ideas
- Define variable N,s,i,j,n to indicate diamond length
- Input n;s=n/2+1;
- Upper half Diamond for (i=1;i<=s;i++)//from 1 to S line;
for (j=0;j<s-i;j++)//Line I, enter the number of spaces in relation to S and I, note each output two spaces;
printf ("");
For (j=0;j<i2-1;j++)//Enter the relationship between Asterisk and I, format asterisk + space
printf (" ");
- Wrap each time after the loop ends;
The lower half of the diamond for (i=1;i<=n/2;i++)//The remaining N/2 line is calculated separately
for (j=0;j<i;j++)
printf ("");
For (j=0;j< (n/2-i)2+1;j++)
printf (" ");
3. Code4. Problems encountered in commissioning process and PTA submission List status note
- The submission list is malformed and partially correct, run on Dev C, and the output diamond is asymmetric;
- Use the # number instead of the space to observe the diamond format, the output * number before the output of the number of spaces is not correct, at the beginning of line s should have no space output, the j<=s-i and j<=i to J<s-i and J<i
Find the output * number before the output of the number of spaces or not, a little less, so that each output of a space to the output of two spaces each time to get the correct results
Topic 2:7-7 fat red envelopes 1. PTA Submission List2. Design Ideas
- The definition array a[7]={100,50,20,10,5,2,1} represents the face value, the array b[7]={0} represents the number of each face value, the definition variable money represents the face value, defines I;
- Enter Money
for (i=0; i<7;i++) This loop is used to calculate the number of sheets of each face value
{
B[i]=money/a[i]; Count the number of a[i] and record it in B[i]
Money-=a[i]*b[i]; Minus the amount that was taken, money is the amount of the next loop
printf ("%3d yuan:%3d zhang \ n", A[i], b[i]);
}
3. Code4. Problems encountered in commissioning process and PTA submission List status note
- Initially did not use the array programming, but uses seven for the statement, the submission result displays the running time-out, the Dev C also cannot run;
- Use the array to do, submit the display format error, the compiler to run the result typographical errors, the topic requirements strictly according to single-digit alignment;
The output statement is%3d, each value is three bits, and the correct result is obtained.
Topic 3:7-10 Simple Calculator 1. PTA Submission List2. Design Ideas
- Define variable char ch= ' 0 ', int i,sum,flag=0,flag used to determine the divisor is zero and illegal character
- Enter initial value sum
- Enter loop while (ch!= ' = ') {input ch
If ch== ' = ', the loop ends;
Input value I;
If ch== ' + ', sum=sum+i
If ch== '-', sum=sum-i
If ch== ', sum=sumi
If ch== '/', when i!=0, sum=sum/i, otherwise flag=1
otherwise flag=1
Output error if flag=1, otherwise output sum
3. Code4. Problems encountered in commissioning process and PTA submission List status note
- Submit multiple parts correctly, prompt for incorrect handling of illegal characters, and run results on Dev C is incorrect;
found that they are using the IF statement, ignoring the judgment of illegal characters, and finally use if, else if the structure, after judging the subtraction, using else to determine the illegal characters, if the illegal characters, flag=1
Get the right answer;
Second, this week's topic set PTA Final RankingIii. Summary of this week's study 1. What have you learned? 1.1 How is a one-dimensional array defined and initialized?
- Defining an array: The general form is type an array group name [array length]
Initialization of the array: Type an array group name [array length]={initial value table}, corresponding from subscript 0, static array not initialized, all elements are 0
1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?
- One-dimensional arrays:
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. The use of arrays in the program, you can let a batch of the same type of variables using the same array variable name, the subscript to distinguish, it is a little expression concise, 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.
- Select Sort method: 1) input n, array a[n]
2) for (k=0;k<n-1;k++) {
Index=k; Index is used to store the minimum value of the subscript
for (i=k+1;i<n;i++)//Find subscript with minimum value
if (A[i]<a[index]) index=i
Temp=a[index];a[index]=a[k];a[k]=temp; }//Minimum element exchange with subscript k element
3) output n The value of the array element in turn
- Bubble Sort Method: 1) input n, array a[n]
2) for (k=0; k< n-1; k++) {
for (i=0; i<n-k-1; i++) {//Compare adjacent elements
If a[i]>a[i+1]) {//If the subscript is not changed before, the value of the interchange element
temp = A[i]; A[i] = a[i + 1]; A[i + 1] = temp;}}
3) output n The value of the array element in turn
Direct Insert Sort method: 1) input n, array a[n]
2) for (k=1; k< N; k++) {
TEMP=A[K]; Used to temporarily save the element that will be inserted. Temp
for (i=k-1; i>=0&&a[i]>temp; j--) {//Find insertion position and move element
A[i+1]=a[i];}
A[i+1]=temp; } insert TMP into the location you are looking for i+1
3) output n The value of the array element in turn
1.5 What is the binary search method? It differs from the order lookup method?
- The basic idea of binary search is to divide n elements into roughly equal two parts, take A[N/2] and X to compare, if X=A[N/2], then find X, the algorithm aborts, if X<A[N/2], as long as the left half of the array a continues to search X, if X>A[N/2], Search for x in the right half of the array A.
Difference: Sequential lookup is characterized by the first element of the table from the beginning of a downward lookup, if there is a target consistent with the element, the lookup succeeds, if the last element still does not have the target element, then the lookup fails, and the binary lookup method is to find from the middle, gradually narrow the scope, for the processing of big data is more applicable, Reduced cycle times and higher efficiency;
1.6 How are two-dimensional arrays defined and initialized?
- Definition of a two-dimensional array: Type an array group name [line length] [column length]
Initialize: The branch assigns the initial value: Type an array group name [line length] [column length]={{Initial value table 0}, ..., {Initial value table K}, ...}, the values in the initial value table K are assigned to the K line in turn;
Order Assignment Method: Type an array group name [line length] [column length]={initial value table}, assign values in turn;
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?
- Matrix transpose: for (i=0;i<n;i++)
for (j=0;j<n;j++)
if (i<=j) {
Temp=a[i][j];a[i][j]=a[j][i];a[j][i];}
Lower triangle: i>=j Upper triangle: i<=j symmetry: I==j or i+j==n-1
1.8 What is the general application of a two-dimensional array?
There are a series of elements with a one-dimensional array, if these elements have certain positional logic, such as matrices, use a two-dimensional array
2. This week's content, you are not what?
- PTA topic in the Nineth division expression--write a tokenizer bar will not do, my practice is to first use a loop to enter a legal expression, until input =, and then use the loop to split the expression and output, but after the output of the number after the line is not, so each output will be output after a character , and then change the line, the problem has not been resolved; Here's my code, look at the big guy to help
- And this midterm test, found that a lot of basic computer theory and some logical operations are not understood, especially the bit operations, and, or, XOR, and so on;
The application of two-bit arrays is not well understood, and loops are often used to solve those problems?