Self-reflection after NetEase's written examination

Source: Internet
Author: User

NetEase after the written examination, the heart empty. Come down also and classmates exchange, perhaps people think I compare water, when I talked about writing that large number of classes, directly denied my segmented addition thought. Although denied, but I can not slack, but not so depressed or self-denial. I should prove myself in the voice of doubt. I can also, and August to get an offer, I began to spell!

First of all to say the choice, my knowledge has expanded, but MySQL, Linux, the lack of knowledge of more. Design Patterns I've seen columns before: Design patterns. But I didn't summarize it. TCP/IP Protocol I also saw the Vamei of the great God, the overall understanding of the line, but the implementation of the details are relatively deficient.

Talk about programming problems, fortunately, I saw before the examination of previous years of the subject of credit, and this time the sub-Apple basically similar. But down and the great God Code communication is still insufficient, when writing code still have to pay attention to a lot of problems.

#include <iostream>using namespace Std;int getrt (int *num, int len) {int av = 0;int total = 0;for (int i = 0; i < Len  ++i) av + = num[i];if (av% len! = 0) Return-1;av = av/len;for (int i = 0; i < len; ++i) num[i]-= av;for (int i = 0; i < Len; ++i) {if (Num[i] > 0 && num[i]% 2 = = 1) return-1;else if (Num[i]  > 0) Total + = Num[i];} return TOTAL/2;} int main () {int len = 0;int *arr = null;cin >> Len;arr = new Int[len];for (int i = 0; i < len; ++i) cin >> AR R[i];int RT = GETRT (arr, Len), cout << RT << endl;delete Arr;return 0;}
The problem with this code is that you can enter only one case. Change to the following.

#include <iostream> #include <vector>using namespace std;int getresult (vector<int> num, int len) {int AV = 0;int total = 0;for (int i = 0; i < len; ++i) av + num[i];if (av% len! = 0) Return-1;av/=  len;for (int i = 0; i < Len; ++i) num[i]-= av;for (int i = 0; i < len; ++i) {if (Num[i] > 0 && num[i]% 2 = = 1) return-1;    if (Num[i]  > 0) Total + = Num[i];} return TOTAL/2;} int main () {int len = 0;while (cin >> len)               //Easy to enter multiple case    {        vector<int> data (len,0);    for (int i = 0; i < len; ++i)        {            int temp = 0;            Cin >> temp;            Data[i] = temp;        }    int RT = GetResult (data, Len);    cout << RT << Endl;        Data.clear ();    } return 0;}
Add a while () loop at input to facilitate input of multiple case. Use arrays to convert to vectors at the same time. Then analyze and analyze the code below.

#include <iostream> #include <vector>using namespace Std;int main ()    {    int n;    cin>>n;    vector<int>v;    int sum=0;    while (n--)        {        int tmp;        cin>>tmp;        V.push_back (TMP);        sum+=tmp;    }    int avg=sum/n;    vector<int>sent;    for (int i=0;i<v.size (); i++)        {        if (v[i]-avg>0) sent.push_back (V[I]-AVG);    }    int cnt=0;    for (int i=0;i<sent.size (); i++)        {        if (sent[i]%2==0) CNT+=SENT[I]/2;        else return-1;    }    return CNT;}
(1) The whole logic is less if the average value is a decimal, it is not divisible when you want to return directly-1. (2) The case of multiple loops is not considered (3) The structure of the code is blurred, and the related logical operations are not separated directly. (4) The algorithm lacks optimization considerations.

So the code is still a lot of room for improvement. The following progress direction.

1. Write code logically, can be summed up as a function is best to write a separate function.

2. Input format, output format need to meet strict requirements

3. The algorithm's space and time efficiency can be optimized as far as possible.

At the end of the article, I vented it. The classmate who despise me, you wait, I will become the great God, wait to see it. Draw the wind a turn, I still want to recognize their shortcomings, check gaps, open-minded learning, thick accumulated thin hair.

Self-reflection after NetEase's written examination

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.