C Language Blog Job--one or two-dimensional array

Source: Internet
Author: User

7-3 Year of birth: 1. PTA Submission List:

2. Design ideas:

Define the control variable i,j,k, year, the number of different numbers n, the year substitution value digit, the same number of variables same; use sum=year+i; add years, record the value of sum with digit digit=sum;count=digit%10;a[j] =COUNT;DIGIT=DIGIT/10, the number of each bit is stored, the sum is re-assigned same=0; A[i] is traversed, that is, nested loops for (k=0;k<4;k++) for (j=k+1;j<4;j++) if (a[k]== A[J]) is same++;
if (same==1&&n==3) break;
if ((same==3| | same==2) &&n==2) break;
if (same==0&&n==4) break;
if (same==6&&n==0) break;
The value of the output I;
Use the loop for (j=3;j>=0;j--) to sequentially reverse the output year;

3. Code:

4. Problems encountered in debugging process and PTA Submission List situation Description:
    • 1. At first did not notice the contradiction of the cyclic conditions, written for (i=0;i>=0;i++), leading to how can not get into the loop, and later with the help of classmates and teachers to correct;

    • 2. Write DIGIT=DIGIT/10 into COUNT=COUNT/10;

    • 3. Later submitted PTA, found n=2 error, how can not understand why wrong, because the answer output and sample, in the classmate help finally know oneself less write a situation, namely same=2, just also have two different situation, and oneself only consider 3 Phase 2 different situation , this is to consider the problem caused by the wrong;

7-2 to find the number of occurrences in an integer sequence: 1. PTA Submission List:

2. Design ideas:

Define the control variable I,j,max the maximum value, n is the number of input integers, a[1000] holds the integer, count2 the most occurrences of the number, COUNT1 statistical statistics of the number of occurrences of each integer;
Input n,scanf ("%d", &n);
The loop input integer is deposited into the array a[1000],for (j=0;j<n;j++) scanf ("%d", &a[j]);
The maximum value is a[0],max=a[0];
for (i=0;i<n;i++) order count1=0;
The most frequently occurring number of statistics
for (j=0;j<n;j++)
if (A[i]==a[j]) then count1++;
if (j== (n-1) &&count1>count2) then count2=count1;max=a[i];
Output "%d%d", max,count2 ";

3. Code:

4. Problems encountered in debugging process and PTA Submission List situation description.
    • 1. At first, the cycle of statistics for (j=0;j<n;j++) was written for the for (j=i+1;j<n;j++), the debug found that this will make the statistics itself is not counted, at the beginning of the thought simply to count each of the numbers from the beginning to the end of the line, Now we have found a more efficient way to write for the for (j=i;j<n;j++), so that although not every number will be fully counted the number of occurrences, only that number in the first time when the total number of statistics, but still can draw the most occurrences of the number

    • 2. If the conditions are met (j== (n-1) &&count1>count2), then max=a[i], but not max=a[j];a[i] is the number to compare, A[j] is used to iterate over the array of numbers;

7-6 Reading Room: 1. PTA Submission List:

2. Design ideas:

Define TIME1[1001],TIME2[10]={0},TIME1 storage of the initial number of books, time2 storage of different days of the total time of borrowing, will time2 elements all return 0;
Define the Count[10]={0},day,i=0,book=1, where count counts the total number of borrowing in different days;
Define h and M, record time and minutes; define CH;
Enter day;
while (I<day)
Input ("%d%c%d:%d", &book,&ch,&h,&m);
if (ch== ' S ' &&book!=0) then time1[book]=h60+m; This is the time to start borrowing different ISBN
if (ch== ' E ' &&book!=0&&time1[book]!=0) then time2[i]=time2[i]+h
60+m-time1[book]; count[i]++; The sum of the borrowing time of the day;
Perform the above cycle when book!=0;
i++;
for (i=0;i<day;i++)
if (count[i]==0) output "%d%d\n", count[i],0;
Otherwise output "%d%0.f\n", count[i],time2[i]*1.0/count[i];

3. Code:

4. Problems encountered in debugging process and PTA Submission List situation description.
    • 1. If you want to return time1[1001] to 0, you need to do it in a loop instead of time1[1001]={0} like the initialization definition;
    • 2.SCANF ("%d%c%d:%d") the space between%d and%c, i.e. scanf ("%d%c%d:%d");
    • 3.I is now 0, so while (i<=day) changes to while (I<day);
    • 4.time2[i]=h60+m-time1[book] instead of Time2[i]=time2[i]+h60+m-time1[book], so as to achieve accumulation;

      Second, this week's topic set PTA Final ranking:

Third, peer-to-peer evaluation of code pairs

Li Qin's code:

My Code:

1. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer?
    • 1. This is a 7-4 simplified insertion sort, my code is mainly set up two arrays, with array a re-arranged after the array B assignment, and Li Qin code is mainly the insertion sort, I think her code is relatively concise, but not easy to understand, my code is more complex, but it may be easier to understand, But still prefer a concise style;

      Iv. Summary of this week's study:
    • How do I store strings in 1.1 C?
      Storage methods and arrays are similar, are a character corresponding to a storage unit, the last one must be 0;

    • 1.2 What is the end flag of a string and why do you want to end the flag?
      Is ' s ', because the operation of a character array can only be used for valid characters and string terminators, so it is necessary to determine whether to end the operation of the character by detecting the string terminator;
    • 1.3 What are the methods for string input?
      Method One: Char str[80]= "HAPPY";
      Method Two: s[0]= ' a '; s[1]= ';
      Method Three: while ((str (i) =getchar ()) = ' \ n ') i++;str[i]= ' + ';
    • 1.4 Numeric characters How to turn an integer, write a pseudo-code?
      number=number*16+hexad[i]-' 0 ';
    • 1.5 16 binary, binary string how do I turn 10 binary? Write pseudo-code?
      if (s[i]>= ' A ' &&s[i]<= ' F ')
      n=s[i]-' A ' +10;
      else if (s[i]>= ' a ' &&s[i]<= ' F ')
      n=s[i]-' a ' +10;
      else n=s[i]-' 0 ';
      Temp=temp*16+n;

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

The detailed list does not understand the place, including the classroom assignment wrong question, the PTA wrong question.

3. Midterm summary

3.1 Why do you think you didn't do well?

3.2 List the wrong questions.

Please select the question, fill in the blanks, change the wrong question, the programming question to give a question to explain why wrong, how to change?
3.3 The second half semester how to adjust C's study?

C Language Blog Job--one or two-dimensional 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.