C Language Blog Job-data type

Source: Internet
Author: User
Tags array definition array length

First, the PTA experimental work Title 1:7-2 Location Code Input Method 1. PTA Submission List

2. Design Ideas

{
Define the character type variable CH1,CH2,CH3,CH4;
Define integer variables, a, B;
Ch1=getchar (); Input value
Ch2=getchar ();
Ch3=getchar ();
Ch4=getchar ();
a=10(ch1-48) +ch2-48+160;//Results of operation
b=10
(ch3-48) +ch4-48+160;
Putchar (a);
Putchar (b);
}

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

Question 1: Just start with two ch, with results but the result is not the same as the answer
Workaround: Add printf behind the CH1,CH2 and find out that the output is ' 1 ', ' 6 ', and understand that there is no ' greater than 10 characters '.

Topic 2:7-8 judge the legal identifier 1. PTA Submission List

2. Design Ideas
定义变量repeat(输入几位数字),count,count1(用于判断结果),n(判断结果),i(用于循环),ch                          输入repeatfor(i=1;i<=repeat;i++){   //循环    n等于0;    count1等于0;    count等于0;如果((ch=getchar())!=‘\n‘){    //输入字符        count1++;     //输入字符的数量        如果((n==0)&&(((ch>=‘a‘&&ch<=‘z‘)||(ch>=‘A‘&&ch<=‘Z‘))||(ch>=‘0‘&&ch<=‘9‘)))  //判断字符是否满足开头的要求        count++;        如果(n==1&&(((ch>=‘a‘&&ch<=‘z‘)||(ch>=‘A‘&&ch<=‘Z‘))||(ch==‘_‘||(ch>=‘0‘&&ch<=‘9‘))))  //判断字符是否满足后面的要求        count++;        n=1;               }

End
If (total count= equals count1)//output result
Output ("yes\n");
Else
Output ("no\n");

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

Problem One: Write code, feel right, no results on dev
Workaround: In the code cut each other, to determine which place and the result is not satisfied, the result is Ch=getchar ()! = ' \ n ' Ch=getchar () and parentheses

Topic 3:7-10 Simple Calculator 1. PTA Submission List

2. Design Ideas
 定义变量n,m,sum,count=0, op;输入n;sum=n;for(;;){    输入op)     如果是等号,结束循环              输入m    如果是+,运行下列式子,依次如下    sum=sum+m;    如果是-    sum=sum-m;    如果是*    sum=sum*m;    如果是-    if(m!=0)  //限制分母是0    sum=sum/m;    else    count++;} elsecount++;//一些不符合要求的加1}如果(count>0)输出ERRORelse输出sum;
3. Code

4. Problems encountered in commissioning process and PTA submission List status note

There's no problem.

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?

One-dimensional array definition to have a type name, array name [array length]
Initialization can be used with static

1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?

The memory is allocated a contiguous number of storage units, and these units are numbered, please see the C Language Book 150 page in the upper right corner
Array name is the first address of the array

1.3 Why use arrays?

You need to reuse some of the previous data under a specific topic, so using arrays and some of the topics with arrays can greatly improve programming efficiency.

1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo-code Presentation-selection method

Define a[10],i,j,k,t,n=10;
for (i=0;i<10;i++)
Input A[i]
for (i=0;i<n-1;i++)//outer loop control, n number of n-1 times {
K=i; / Suppose the current first number is the maximum value, which is recorded in K /
for (j=i+1;j<n;j++)/ from the next number to the last number to find the most value /
if (A[k]<a[j])/* If the condition is met

    k=j;         /*则将其下标记在k中*/ 在转换数值大小

for (i=0;i<10;i++)
Output A[I])

Bubbling method

Define a[10],i,j,t;
for (i=0;i<10;i++)//Enter 10 values
Output A[I]
for (j=0;j<9;j++)/ outer loop control sort count, n number of rows n-1 times /
for (i=0;i<9-j;i++)//inner loop for J-times comparison n-j Times
if (a[i]>a[i+1])/Match condition reverse order exchange *
{T=a[i];
A[I]=A[I+1]; Convert values
a[i+1]=t;
}
for (i=0;i<10;i++)//output results sequentially
printf ("%d", a[i]);

Direct Insert Sort

Define a[10],i,j,t;
for (i=0;i<10;i++)
Input A[i])
for (i=1;i<10;i++)/ Outer loop control number, n number from 2nd to last n-1 times insert /
{
T=a[i]; / Store the number of inserts in the variable T /
for (j=i-1; j>=0 && t>a[j]; j--)/ Find insertion position in ordered sequence (subscript 0 ~ i-1) /
A[j+1] equals a[j]; / If the insertion position is not found, move the element back one position /
A[j+1] equals t; / Find insertion position, insert /
}
for (i=0;i<10;i++)
Output A[I])

1.5 What is the binary search method? It differs from the order lookup method?

is to take the median size of the number and the number to be compared, if the unknown origin number is greater than the median number, the middle number and the large number of the middle number
To be compared in order until it is found or cannot be found.
The difference is that the efficiency of the 2-point lookup method is high, and the sequential lookup method is inefficient

1.6 How are two-dimensional arrays defined and initialized?

Type an array group name [President degree] [column length]
Simple with static initialization, just add {0}

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.

Define a 2-D matrix Inta[3][3] (here we introduce 33,nN)
123
456
789
for (i=0;i<3;i++)
for (j=0;j<3;j++)
If I is greater than or equal to J
A[I][J] equals a[j][i]//swap array size
J^=i^=j^=i//Column Exchange
Output results
147
258
369

1.8 What is the general application of a two-dimensional array?

Matrices and some programs that use 2-d arrays can greatly increase code efficiency

2. This week's content, you are not what?


1. There is no train of thought on this topic, there is a complex code, basically do not see what it is doing
2. The definition of the personal feeling array is not very difficult, difficult is the use of it skillfully, for the bubble method feel is not very familiar with the ranks of the Exchange master is not very good
3. The priority for the character is not clear.

C Language Blog Job-data type

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.