Learn C + + have to read an article (ZZ)

Source: Internet
Author: User

Choose a Blog from yelky

Learn programming some of the situation I really have feelings, this interview makes me deeply understand the failure but also harvest
A lot. What I'm going to say will be divided into three parts:

1. It's my interview details.

2. It's from the interview.

3. What I should do now.

Of course these words are to a large extent my personal opinion, it is impossible to completely get everyone's approval, so in
If some of my friends feel that they are in great discrepancy with me, please do not mind or attack me,
As I have not said, welcome to contact me to discuss these issues. My email:wutao8@263.net.

1. Interview Pass

About a year ago, I received an interview notice from the Realtek Suzhou Company in Taiwan, informing me that February 21
To the Suzhou Industrial Park for an interview, I received a few days after the interview, I have studied some specialized courses, especially C + + and
Data structure, due to the university years, I have been specialized in these aspects, coupled with the passing of advanced Programmer's examination
, for some commonly used algorithms I have almost reached the point of the chest, then the feeling is if asked
I should have no problem with these aspects of my problems.

On the 21st I was arranged for an interview at 4:30, a technician gave me a solo interview and asked some Jane
Single question after he gave me a programming topic, the topic is this:

(due to the specific interview topic more cumbersome, I will be the core of the ideas extracted from the decomposition into two independent
Simple questions, there may be problems decomposition of improper, please forgive me, the actual interview a problem but more than its
Much more complex, and involves some advanced mathematical transformations)

1 Write a function to calculate the value when the parameter is n (n very Large) 1-2+3-4+5-6+7......+n

Hum, my heart sneer at a sound. Unexpectedly so simple, I am a little nervous mood immediately relaxed.


So I soon gave my solution:

LONG fn (long N)

{

Long temp=0;

int i,flag=1;

if (n<=0)

{

printf ("Error:n must > 0");

Exit (1);

}

for (i=1;i<=n;i++)

{

Temp=temp+flag*i;

Flag= ( -1) *flag;

}

return temp;

}

Get. When I looked at the interviewer with a look of anticipation, he smiled and told me that the results were definitely
is no problem. But when n is very big, I this program execution efficiency is very low, in the embedded system development,
The efficiency of the program is very important, it is good to make the CPU less execute a command, he let me see this program also
What can be modified place, the program optimization. After hearing these words, my mood was a little heavy.
Heavy, did not expect his strict requirements, then I have a rigorous analysis of the procedures, gave the improved side
Case.

LONG fn (long N)

{

Long temp=0;

int j=1,i=1,flag=1;

if (n<=0)

{

printf ("Error:n must > 0");

Exit (1);

}

while (j<=n)

{

Temp=temp+i;

I=-i;

i>0?i++:i--;

j + +;

}

return temp;

}

--

Although I am not sure that this algorithm is optimal, but compared to the previous program, I will all relate to
The statement of the multiplication instruction is changed to execute the addition instruction, which achieves the requirement of the problem and shortens the computation time.
Many. And the price is simply to add an integer variable. But now my confidence has withstood a little blow, and I
Skeptical interviewer, he smiled and said to me: "Yes, this program is really efficient
A great improvement. "I have a anxi in my heart. But he went on to say that the program still failed to meet his requirements,
I was asked to give a better plan. Oh, my God. There is also optimization. I was really a little crushed, and after a while, I
Ask him to give his plan. Then he gave his procedure very readily.

LONG fn (long N)

{

if (n<=0)

{

printf ("Error:n must > 0");

Exit (1);

}

if (0==n%2)

Return (N/2) * (-1);

Else

Return (N/2) * ( -1) +n;

}

Funny, I was dumbfounded, didn't think he was meant to, so simple code I really can't write
, but why didn't I think about that? What he said was not wrong, when N was big and big, these three
The difference between the running time of the program is simply different. When I was about to say something, he started talking.
: "Do not think that the CPU faster than all the problems are pushed to do it, the programmer should be the code excellent
To optimize, we can do in no way to let the CPU do, because the CPU is for the user Service, not for our


Programmer service. "What a wonderful language I don't want to say anymore." And then the second question.
Problem:

2). He asked me to use a technical programming method to implement the function of two functions with a function n as
: Fn1 (N) =n/2!+n/3!+n/4!+n/5!+n/6!

FN2 (n) =n/5!+n/6!+n/7!+n/8!+n/9! Now use a function fn (int n,int flag) to implement
, when flag is 0 o'clock, realize fn1 function, if flag for 1 o'clock to achieve fn2 function. His demands are still efficient,
Efficiency, efficiency. To be honest, if I am in a good mood I should be able to give a better algorithm, but I
There was really no mind to think about it, I scribble some of the formula like 6!=6*5! on the paper after straightforward
When he told him to give his answer. The interviewer didn't say anything, giving his ideas:

Defines a two-dimensional array float t[2][5] deposited in {{2!,3!,4!,5!,6!},{5!,6!,7!,8!,9!}
And then give a loop:

for (i=0;i<6;i++)

{

Temp=temp+n/t[flag];

}

Finally, the calculated value is obtained. Oh, a typical space to change the time algorithm.

It took a total of 50 minutes and 10 minutes to chat with him casually and talk about
Programming and the problems of life, I was already very relaxed, because I know this interview results only one
Failed 5:30 the interviewer asked me to wait for the notice, so I left their company. This is the whole interview.
A pass.

--

2. The thought of the interview

It's really a failure. I remember the day it was raining so much, the temperature was low, I was walking and thinking, from 5:30
Until 7:30, the whole body was soaked, cold and hungry, but I just keep walking, the mind is full of doubt
Confused, I also want to let the rain to wake myself up. See some of the friends here may think that the interview topics are not like
I'm sure you'll get all the answers right, because I never doubted the Chinese programmer
Ability, I think China has the best programmers in the world, I have never considered myself a master, so I do not
Coming out doesn't mean that Chinese programmers are worse than programmers in Taiwan or anywhere else, so I'm from my point of view, I
I want to talk about some thoughts:

Good programmers all over the world, China is no exception, but I am puzzled: In the end China and
What is the proportion of good programmers in Taiwan or abroad? Taiwan I don't know, China 100 programmers
How many of them are good? I am not at all, from the above performance is enough to explain everything. is 1. 5 A
。 10 A. 50 A. This number I do not dare to guess, afraid of netizens a scolding, then how many people in our country
Learn about computers. Take our school, computer 97 level 4 classes, 98 Level 5 classes, 99 level 10 classes, 20
class 00, 17, more people, the teacher how to do. Our school's practice is to let the postgraduate class, then. Fill
Test a catch a lot, a lot of make-up fee fell into the school's pocket, but also said that the quality of the students are low. Really
Is funny, I do not know what the school is doing for what, for the domestic development of a large number of programmers. Students
Can you really learn computer knowledge? Well, I dare say, learning programming students and excellent programmers in our school
(Note that I mean good, only a few bad programs are not the number of people) the proportion should be 100:0.1

In this proportion, although we learn to program in China are overwhelming, but think how many people can really
is to contribute to the development of China's software industry, how many people can really write excellent program name Yang overseas.

Since I learned programming, whether it is self-study or teacher guidance, has always been to solve the problem is good, compiled
Program to the line, my question is: we have a real emphasis on the efficiency of the program, the quality of the program. We
Have a careful analysis of what we write, see if there is any improvement in the place to see if there is no simple way
To achieve the same goal. I ask myself, I find that I have never been to the program I wrote
optimization, which is the most detailed test, and then debug, but that's enough. These days I occasionally hair
Now I have written a game, it was a year ago I just joined Vcroad.net as a member of the time, feeling
Sleep should get something out of it and then spend one weeks writing it. The program is not complicated, but with
To a lot of data structure of things, also used some wonderful algorithms, plus Windows interface and game
Can play sex, finished after a lot of praise, I really admire myself. But now look: not a
Sentence annotation, a lot of ugly function names such as: void Chushihua (), a lot of unnecessary variables, you can
With simple statements to complete the work I use the gorgeous algorithm, a lot of use of global variables ...
, more than 600 lines of the program in addition to running is a piece of crap. If I could hear some negative comments a year ago,
, I might have been enlightened a little earlier, but since the original code was posted on the website, it was a compliment.
, no one has asked me for an improvement in procedure, which is a question. It's worth thinking about.
Ah.

There is another doubt: what we say and do is really the same. When I was at school, I used to go to college.
Sent to host a computer contest, asked a teacher out of the final question, mainly some algorithm problems, which
A teacher is probably the only teacher I have admired since I went to college, from program debugging to scoring, for each program
are carefully analyzed for their time efficiency and spatial efficiency, and then integrated scoring, 40 of people's papers, the teacher from the afternoon
Three o'clock debugging until the evening 10 o'clock, some of the wonderful statements added after the annotation. I'm so glad I met you.
To such a teacher and to do in-depth communication with him, but in hindsight, there has been an unpleasant thing, in more than
The student who won the second place in the race found me and said that he should get full marks for all the debugging of the program and should be
First, I said but he, finally pulled up his original program and the first name of the original program contrast, yes, two
The order is running very well, at this time, the classmate said: "My program written very simple and clear, just a few
The line completes the question request, but his writing is a lot of, why give him more than the cent that gives me. "I
At that time was very angry, if not the teacher is responsible, then now the first and second position really to each other
Yes, come on, it's not the number of lines in the program. The higher the quality of the program, I remember talking to him about it.
Truth, and finally persuaded him. Haha, but I, can only say that, I do not know how many people like,
It's so articulate, but it's never been valued in the heart.

3. I'm going to do that.

In fact, the day I think of more than that, but I do not want to say, because I guess read this article
The article's netizen probably all has full's feeling, full's complaint, borrows this article to vent is not I thought
To achieve the purpose, in the above I scold the worthless is not to belittle themselves, but in some ways I really
Wrong, or deviated from the right direction, now is the time to correct the direction and regroup, like
As I said earlier, I believe China has the best programmers in the world, and I believe my level will not always protect
With the status quo, I'm going to pack up my whining and really do it.

It was really a coincidence that when I wrote this, I found this handbook on the Internet, and I didn't know it was a harbinger.
, but I thought if I had been doing it the following basic principles, I would have realized my
Ideal---an excellent software designer!

(The following text is not my original, is I occasionally found on the internet, I am really very lucky to see
These, this article also with the following text and end, I sincerely hope you can get from this article
Hair, this article welcomes everyone to reprint, you can not write who the author is, but please write on the original vcroad.net
Chuang, thank you for your support)

Author: Kingdee Middleware company CTO Shangong Hillock

Unknowingly do the software has been done for ten years, there is the joy of success, but also the pain of failure, but always dare not to say
I am a master, because and my mind of the real masters are compared, still too far. The world has not become
A shortcut for a master, but some basic principles can be followed.

1. A solid foundation. Data structure, discrete mathematics, and compiler principles, these are the basis of all computer science
If you don't master them, it's hard to write a high-level program. According to my observation, the person who studies computer science is more than
People who study other majors are better able to write high quality software. The program will be written by everyone, but when you find it written to a certain distance
When it is difficult to improve, you should consider whether to go back and learn these basic theories. No
To learn oop from the beginning, even if you are proficient in oop, you may be helpless when you encounter some basic algorithms.


2. A rich imagination. Do not rigidly adhere to the fixed way of thinking, encounter problems to think of several solutions
A solution to the problem, try a method that other people never thought of. A rich imagination is built upon the foundation of rich knowledge
In addition to the computer, more than other disciplines, such as astronomy, physics, mathematics and so on. In addition, many
It's also a good way to watch sci-fi movies.

3. The simplest is the best. This may be a rule that all science follows, and so complex a quality
The principle of interchange in Einstein's eyes is just a simple formula: E=MC2. A simple way
Easier to understand, easier to implement, and easier to maintain. Priority should be given to the simplest side when encountering a problem
Case, only the simple solution can not meet the requirements and then consider the complex scheme.

4. Not a dead alley. When you encounter obstacles, you may as a temporary stay away from the computer, look out the window scenery,
Listen to light music and chat with friends. I play games when I have problems, and it's the kind of extreme violence
Fight game, when the part of the brain that is in charge of the game is extremely excited, the part that is responsible for programming
The brain cells get a good rest. When I get back to work, I find that the problems are now
can be solved.

5. The thirst for answers. The history of human science is a process of longing for answers, even
Only a small part of the answer is worth paying for. As long as you believe, you must find the problem
The answer, you will be able to devote energy to explore, even if the end did not get the answer, in the process you will learn a lot
Things.

6. Communicate more with others. Three-person line will have my division, perhaps in a casual conversation with others, you can
To give the spark of inspiration. More on the Internet, to see other people's views on the same issue, will give you a lot of inspiration.


7. Good programming style. Pay attention to develop good habits, code indentation, variable naming rules
Always be consistent. Everyone knows how to exclude errors in the code, but often ignore the error of the annotation.
Annotations are an important part of a program that makes your code easier to understand, and if the code has
Clearly express your thoughts, you don't have to annotate them, it's even worse if the comments and code don't match.
Cake.

8. Toughness and perseverance. This may be the biggest difference between a "master" and a general programmer. A Good Programm
ING is weat and 1 offee. Masters are not geniuses, they are in countless days and nights in the mill
practiced out of it. Success can bring us great joy, but the process is extremely boring. You might as well do
A test, find a list of prime numbers within 10000, copy them all down, and then check them three times, if you can
Complete this work without interruption, you can meet this one.

These are a few years of my programmer's career experience, I hope to be able to help.

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.