C Language Blog Job--character array

Source: Internet
Author: User

I. PTA LAB Assignment 1:7-1 string converted to decimal integer 1. PTA Submission List

2. Design Ideas
定义数组str存放初始字符串,line存放十进制字符串,number表示十进制数,flag为判断标志  遍历数组,while((str[i]=getchar())!=‘#‘)   i++输入初始字符串,str[i]=‘\0‘将结束符存入数组  for i=0 to str[i]=‘\0’从0到结束符       如果k=0并且str【i】为‘-’,flag自增       判断字符串是否为十六进制数,是的存放在line【k】中 在新数组line中存放结束符  定义number初值为0  for i=0  to  line【i】=‘\0’,将十六进制数转为十进制数           if(line[i]>=‘0‘&&line[i]<=‘9‘) number=number*16+line[i]-‘0‘;数字符转为10进制        else if(line[i]>=‘a‘&&line[i]<=‘f‘) number=number*16+line[i]-‘a‘+10;小写字母转为10进制        else if(line[i]>=‘A‘&&line[i]<=‘F‘) number=number*16+line[i]-‘A‘+10;大写字母转为1-进制  如果flag和number都不等于0;输出-number       否则输出number
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
  • Judging the condition of negative numbers has not been written right, refer to the students after the code to write to

    Topic 2:7-2 counts the number of words in a line of text 1. PTA Submission List

    2. Design Ideas

    3. Code

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

  • The length of the string defines a small, run-time error, and the Count self-increment of the judging condition begins at the beginning of the flag=1, watching the group of classmates after discussion to correct

    Topic 3:7-3 Find the longest string 1. PTA Submission List

    2. Design Ideas

    定义N为输入的字符串数目,max存放最大的字符串长度,max初值为0 ,temp为最长字符串的下标 ,定义二维数组str便于输入字符串 ,定义数组a存放每一个字符串的长度   输入N   for i=0  to  N   输入N个字符串   for i=0  to  N   a[i]=strlen(str[i]  把每个字符串的长度存放在数组a中   for i=N-1   to  0  将a中每个字符串的长度与max比较,大的赋给max,记下下标temp=i  输出最长的字符串
    3. Code

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

  • At first, it was impossible to enter the string Xiang, and then a two-dimensional array was defined, and then it was lost.

    Second, this week's topic set PTA Final Ranking

    Third, peer code peer review 1. Peer evaluation of the names of students

    Wang Hongyue

    2. My Code, mutual evaluation of the student 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.
  • Wang Hongyue Terminator hit wrong, resulting in a paragraph error, personal feeling my code is more efficient and relatively concise

    Iv. Study Summary of the Week 1. What did you learn? 1.1 How pointer variables are defined

    类型名 *指针变量名(类型名指定变量所指向变量的类型,*为指针声明符)

    1.2 pointer addition operation in which case, can the 2 pointer variables be added to each other?
  • (p) + + means adding 1 to the variable pointed to by the pointer,p++ equivalent to * (p++), moving the integer unit down
  • int p=a; p is a[0], * (p+1) is a[1]
  • Two pointer variables cannot be added

    1.3 The pointer does not assign the initial value, direct use, what happens, please use DEVC verification, and show?

    Program crashes

    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?
  • int I and float f use pointer I and pointer p as formal parameters.
  • An argument is represented by an address.
  • Change the memory directly to change the value of the argument.

    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[80],*p; p=a;(或者p=&a【0】)

    1.7 How do I define a character pointer to a string? Where is the initial position after the pointer points to the string?
  • Example: Char *sp= "point"
  • The initial position is the address of the first element of a 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?


    More direct data transfer to the main function

    2. What is your content this week? 2.1 Class allocation and how to revise the wrong questions.
    指针预习作业第一题拆分实数的整数与小数部分,参照上面总结1.4
    Pointer and array Preview job
  • 1. Read the program to assign an initial value to the pointer before the second loop p=a
  • 2. Fill in the blanks

    P+n max<*q num
  • 3. Brief answer

    2.2 Others not? How are we going to solve

    PTA character Array question fourth, question eighth, title nineth. Check the data, look at the code of the big boys.

    3. Array on-Machine exam summary 3.1 The wrong question, please list?

    It was a bad test and it was wrong.

    3.2 Wrong question How to revise, why wrong?
  • Still did not learn solid, only to learn the surface of the fur
  • Do the exam again, not the place to ask the person who wrote the right, compare the code of others, find the most suitable for their own

C Language Blog Job--character array

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.