2018 on C language Programming (Advanced) Jobs-2nd time jobs

Source: Internet
Author: User

Job Requirements Two
    • Topic 6-7 Removing numeric characters from characters
      1, design ideas:
      (1) The first step: the main requirement is to delete the characters in the number of characters, my primary idea is to pass through the array if the number encountered, delete it, the non-numeric character after the move forward;
      The second step: according to this idea, we first define two cyclic variable i,j, and then use the while conditional statement to judge the numeric characters, then delete each one, then move forward;
      2. Experiment Code:

      #include "stdio.h"void delnum(char *s){int i = 0,j = 0;  while(s[i] != ‘\0‘) {      if (!(s[i] >= ‘0‘ && s[i] <= ‘9‘)) {          s[j] = s[i];          j++;    }      i++;  }   s[j] = ‘\0‘;}
         3、本题调试过程碰到问题及解决办法                本题是字符问题,当我在遇到这个问题的时候,只是有想法,知道怎么去做,但是却不知道怎么去用if条件来判断出数组中的是否含有数字字符。简单的说我只会构思,不会去写成代码。其主要问题是在

is not to write this condition;
Correction method: I went to the site to find the next problem, see a lot of big Guy's program, their code way to write a lot of, after I found this condition, then successfully write this topic.

  • Topic 6-8 Statistics substring occurrences in the parent string
    1, design ideas:
    (1) The first step: first of all, to find out the number of substrings in the parent string, in the traversal of the array, the use of the IF condition statement to judge one by one;
    Step two: In the process of traversal, Loop variable to add one by one, instead of looking at the number of characters in the substring, so that the more accurate to find the number of occurrences; (self-sensing algorithm is more troublesome, but really can not think of a simple algorithm, only will be used)
    2, Experiment code

      #include <stdio.h>int Fun (char *str,char *substr) {int result=0,i=0;for (i=0;str[i]!= '}; i++) {if (Substr[0]==str[i]    &&substr[1]==str[i+1]&&substr[2]==str[i+2]) {result++; }}return result;  
      3, the problem debugging process encountered problems and solutions;  
  • Topic 6-9 the remaining characters in a string in descending order, except for the kinsoku characters
    1, design ideas:
    (1) The first step: the topic can follow the previous non-character bubble sort method to achieve this problem, but in the traversal of the array, go out two;
    The second step: according to this idea, first define the loop variable, then iterate over the array (note: In the traversal of the array should be careful not to include the first and the first two) and then follow the bubble method to sort;
    2. Experiment Code

    #include <stdio.h> int fun(char *s,int num) {int i=1,j=1,max;for(i=1;i<num-3;i++){    for(j=1;j<num-2;j++)    {        if(s[j]<s[j+1])        {            char swap;            swap=s[j];s[j]=s[j+1];s[j+1]=swap;         }      }  } }
         3、本题调试过程碰到问题及解决办法           本题没有问题;
  • Topic 7-1 Output Student Scores
    1. Design Ideas
    (1) The first step: according to test instructions, first of all to define a number of related variables, such as the number of students N, cyclic variable i, and so on;
    The second step: after the creation of memory dynamic storage, (this I follow the teacher in class to copy copy, I understand that the content is not many, later I also went to the internet to check a lot of relevant dynamic storage related tutorials, but also a little understanding, but still not understand the profound)
    The third step: after the dynamic storage is created, the contents (scores) are stored in the array, and the sum can be summed at the same time so as to carry out the averaging operation after the storage.
    The fourth step: after the storage, the average, then iterate over the array to find the maximum and minimum value, (at this time the maximum and minimum variables should be initialized to the first address element of the array, easy to compare) after the array to find the maximum and minimum value;
    Fifth step: Finally, the output can be carried out according to the requirements of the topic;
    (2) Flowchart:

      2、实验代码
    #include<stdio.h>#include<stdlib.h>int main(){int n=0,i=0,*p,sum=0,max=0,min=0;double average=0;scanf("%d",&n);if((p=(int*)calloc(n,sizeof(int)))==NULL){    printf("Not able to allocate memory.\n");    exit(1);}for(i=0;i<n;i++){    scanf("%d",p+i);    sum=sum+*(p+i);}average=(double)(sum*1.0/n*1.0);max=*p;min=*p;for(i=0;i<n;i++){    if(max<*(p+i))    {        int swap=0;        swap=max;max=*(p+i);*(p+i)=swap;    }}for(i=0;i<n;i++){    if(min>*(p+i))    {        int tmp=0;        tmp=min;min=*(p+i);*(p+i)=tmp;    }}printf("average = %.2lf\nmax = %.2lf\nmin = %.2lf",average,(double)max,(double)min);free(p);return 0;}
      3、本题调试过程碰到问题及解决办法         错误信息1:


    The problem is that I put Max and Min's initialization in the For loop, which leads to a point at the time of submission;
    Correction method: After this error, I was also very puzzled, because I am typing an example of what is right but I can not cross that point. After I also tried the teacher said the single-step debugging, in the course of debugging I found that each time in the For loop will be Max and min in the initialization sequence, then only slightly suspicious, because I am still very inertial to think that even if the initialization is not a problem, because the results of the output is still correct. But it is always difficult this point, after I went to ask classmates, in the help of classmates, but also pointed out the problem, and finally I put Max and min initialized to the for before the last pass.

2018 on C language Programming (Advanced) Jobs-2nd time jobs

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.