荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: selahx (宿醉未散,早梦半醒), 信区: ACMICPC
标  题: Advice for Beginners (zZ)
发信站: 荔园晨风BBS站 (2005年04月23日12:36:53 星期六), 站内信件

Advice for Beginners
Disclaimer
First of all, all that are written below come directly from my experie
nce as programmer and also common sense. Any resemblance or similariti
es with Shahriar Manzoor's advice or anybody else's is coincidental.


------------------------------------------------------------------------------
--

In this page, I would like to say a few things that you might be inter
ested in making you a better programmer. You may disagree with me. Tha
t's fine. Everybody has their own opinion. However, I'm sure there are
 at least one thing that you will agree with me ^_^.

In doing every problem, anything that the problem maker consider important.

It might be something that you think is important or might not. Even t
he silliest thing can be an important thing.
Do not make any assumption unless you have to.
Say, if the problem statement doesn't state the limit of the input, do
n't assume that the limit is N. Ask first. If you don't get any satisf
ying answer, you may then assume (also take note of that assumption) o
r do as in Shahriar's advice (making a simple dummy program).
Outline your program, say in pseudocode (daily language).
This is an important issue. You may say that this is time consuming, e
tc., but by doing so, you usually eliminate any major mistake that may
 arise.
Use variable names that you can relate to.
Use wordy names if you have to, although it is not advisable especiall
y in a time-limited competition. By doing this, you allow yourself to
cut the time needed to figure out what the variables are for when you
debug your program. I remember doing a contest in my early year as pro
grammer. I used alphabet as my variables. If I am to explain that part
icular program today, I might not be able as I can't remember what the
y are for.
Make simple comments at places you consider important.
It has the same purpose.
Use indentation and blank lines.
Again, same purpose. However, when size does matter, you might want to
 eliminate all unnecessary blank spaces.
Watch out for any limitation.
Still fresh in my mind, I used signed 16-bit integer for a problem whe
re the input can go up to 50000. That particular mistake made me lose
the entire problem.
In connection with above, use the largest possible variable type.
Watch out though, if the problem specifies integer, you use integer ty
pe, not floating-point type. This advice only applicable when there is
 no or extremely big space-limit. As you grow, you may find this parti
cular advice unimportant. The smaller the variable type, the faster th
e program run.
Simple example, compare adding two 32-bit integers and two 16-bit inte
gers. The former need 32 adding process while the latter only need 16
adding process. Of course, you have to watch out for the limit.
In a competition, watch out for execution-time limit.
Efficiency is important. But also take this into mind, don't be too ef
ficient if it makes the program a lot complicated. Always try to be si
mple. If you find that your program too slow, first of all try to thin
k for another way. If you can't find any, you then develop short cuts.

Get used to the platform.
From what I heard, using "Enter" can give different results in differe
nt platform. Say on Linux, you might only get CR (Carriage Return), bu
t on Unix, you might get LF (Line Feeder) or the other way around, I d
on't really remember. This can get really annoying especially in readi
ng the input. There shouldn't be any big trouble for C users, but for
Pascal users, say "bye bye" to ReadLn.
End of Input <> End of File!!!
This is very tricky. I've found at least 7 different types of input. T
he one with additional character after the end of the input, the one w
ith no LF character, the one without CR character, etc. The best way t
o get used to this problem, is to follow the advice below.
Practice, practice and practice. I know, this is the most ... part, bu
t still it's unavoidable. If there is any short cut, I would have take
n it. :(
Say, if you have any comments or any addition you would like to make,
you are welcome to do so. E-mail me at IlhamWK@themail.com.

--


※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.64.1]
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 210.39.3.80]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店