C-character Array

Source: Internet
Author: User

First, the PTA Laboratory work Topic 1: Count the number of words in a line of text 1. PTA Submission List

2. Design Ideas
定义一个长度为1000的字符数组str[1000]在定义 i=0,cnt=0;cnt用来记录单词的个数while  str[i]=‘\n‘既输入回车时结束字符的输入str[i]=0;设定结束的标志for i=0 to str[i]=‘\0‘   if str[i]!=‘ ‘&&str[i+1]==‘ ‘;如果这个字符不为空格,并且下一个字符为空格。         cnt++;让cnt+1;   if str[i]!=‘  ‘&&str[i+1]==‘\0‘如果此字符为最后一个字符且不为空格结尾。        cnt++;输出 cnt 的值表示单词个数。
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

At the beginning of the code is this, initially did not consider the end is a blank case, thought that CNT will only be recorded to
Last, and then let the final output when CNT is added 1. The result is wrong.

After discovering the problem, I added an if statement to solve the problem of whitespace at the end, and all spaces.
However, there is still a problem with a segment error and a run timeout.

Then I added the length of the array to solve it.

Topic 2: Identification of identity card 1. PTA Submission List

2. Design Ideas
首先定义变量 n z=0 sum =0 sum计算前17位的加权求和,z是sum %11 后的数定义字符数组 m [12] ={"10X98765432"};和数组a [17] ={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};a数组用来表示权数。输入n的值,     表示判断的身份证的个数。定义 flag=2       用来判断身份证号的准确性定义一个长度为18的字符数组     line[18]while (n)            即当n等于0的时候结束循环getchar ()       来存放之前输入完n之后的回车。 for i=0  to i=17      输入line [i]的值for i=0 to i=17     if line[i]    不为数字,   则,flag=0;if (flag)         当flag 不为0 的时候    sum=sum+(a[i]*(line[i]-‘0‘));    计算加权求和的总数sumz=sum%11,   if (line[17]!=m[z]),         说明校验码不正确             flag=0; if (flag==0)    输出line  并让 flag=1 在重新定义初值    sum=0;z=0;  判断下一个身份证号 n--   在while 的循环外判断  if (flag==2) 说明以上身份证都正确 ,       则输出All passed
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

I did not define flag=2 directly at the beginning of the flag=1 to judge, but in each
Determines whether the output of all passed is affected when a re-assignment is completed after determining an identity card
So let the flag=2 flag=1 each time it is re-assigned, and it will be solved.

Topic 3: Tibetan head poem 1. PTA Submission List

2. Design Ideas
# # #3. Code! [] (Http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210153741021-554041627.png) # # #4. The debugging process encountered problems and PTA submission list situation. The problem was originally wrong in, than knowing that two characters represent a character, that is, a character represents a number, the result of the output of the answer is wrong # Two, this week's topic set of PTA Final ranking! [] (Http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210154047661-1405305900.png) #三, peer code pairs of peer review # #1. Mutual evaluation Classmate name Zheng Jialiang # #2. My code, peer-reviewed classmate code My Code:! [] (http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210172712943-923243078.png) Zheng Jialiang code:! [] (http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210172928943-379826779.png) # #3. What's the difference between me and my classmate code? What are their advantages? What style of code do you prefer? If the classmate code is wrong, please also help point out where the problem of my code, although more than two lines, but I think my idea will be better, I only use two judgments, I can meet his four judgments, so I think my code will be better Oh # Four, this week to learn to summarize # #1. What did you learn? # # #1.1 How pointer variables are defined-(1) Defines the general form of a pointer variable as a type name * pointer variable name # # #1.2 pointer addition operation in which case, 2 pointer variables can be added? When you explicitly define a pointer to an exact address, the pointer adds up to make sense. # #1.3 The pointer does not assign the initial value, the direct use, what will appear, please use DEVC verification, and show? A: If you do not assign the initial value to the pointer, the pointer will randomly point to an address, which will harm the program, causing the system to crash and stop running. [] (Http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210160027365-565938257.png) # # #1.4 Class assignment on the integer and fractional parts of the floating-point number, please use DEVC to verify the implementation, and show it in this map, andIndicates which sentence is a pointer variable to make a function parameter, and how the function argument should be represented. What is the use of pointer variables for function parameters?! [] (http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210161729833-1494015546.png)! [] (http://images2017.cnblogs.com/blog/1233828/201712/1233828-20171210161754255-484302687.png) void Slipfloat ( float X,int *intpart,float *fracpart) This is a pointer variable as a formal parameter, in the keynote function, the address of the variable or the pointer of the variable as an argument, in the function, the pointer type parameter to accept the address of the variable, and change the value of the parameter points to the variable. # # #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 # # #1.6 How to define a pointer variable to an array, how to use a pointer variable to represent an array element?  P= A; or p= &a[0]; Represents an array element: P=a+1 or p=&a[1].## #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 *pchar line[80]p = line; Its initial position at the base site # # #1.8 Use a character pointer to manipulate a string, such as a design function to implement a string connection, to present the code in this map. What are the advantages of the method that indicates the pointer represents a character?
Include

void Link (char p1,char p2);
int main ()
{
Char line[160]={0},str[80];
Char p1=line,p2=str;
int i=0;
while ((Line[i]=getchar ())! = ' \ n ') {
i++;
}
line[i]=0;
GetChar ();
i=0;
while ((Str[i]=getchar ())! = ' \ n ') {
i++;
}
str[i]= ' + ';
Link (P1,P2);
Puts (line);
return 0;
}
void Link (char p1,char p2)
{
int i=0,j=0,index=160;
for (i=0;i<160;i++) {
if ((p1+i) = = ' + ') {
Index=i;
}
if (I>=index) {
(p1+i) =* (P2+J);
j + +;
}
}
}

说实话,我也不知道好处是什么,比较灵活吧#2.本周你不会内容有什么?###2.1 课堂派错题罗列及如何订正。- (1)以下选项中,对基本类型相同的指针变量不能进行运算的运算符是()。不会可以用DEVC去实践验证.进过老师讲解直到指针只能进行减法运算,不能进行加减乘除。- (2) 若有语句:int *point,a=4; 和 point=&a; 下面均代表地址的一组选项是C、*&point,*point,&a  我一开始是选择这个,刚开始没掌握嘛现在直到前两个都不是表示地址。###2.2 其他不会的?打算怎么解决对于指针的运用还是不太熟悉,尤其是指针数组的运用。##3.数组上机考试小结###3.1 那题错了,请罗列?6-2 jmu-c-二维数组转置并按列排序7-2 jmu-c-十进制转16进制7-3 jmu-c-输出字符间的字符子串7-4 数组元素的删除(15 分)以上的题目错了###3.2 错题如何订正,为什么错了?6-2 jmu-c-二维数组转置并按列排序,这题在装置的地方对于j 的范围没定义好,结果有重新装置回去了
    for(j=0;j<n;j++){        if(i<j){            t=a[i][j];            a[i][j]=a[j][i];            a[j][i]=t

```
I'll just add a condition before the conversion.

7-2 jmu-c-Decimal Turn 16 binary system This question still do not know how to do, haven't thought out, but I have a trickery method, with%x output
7-3 jmu-c-The character string between output characters forget the time there was stuck, anyway, now it's done.

C-character Array

Related Article

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.