+ 2
This code is the solution of the new driver's license problem but it get's very big !!
https://code.sololearn.com/c19ORplwIsfB/?ref=app Can anyone optimize this code more efficiently to make it shorter !!
4 Antworten
+ 2
1. You can avoid blank lines.
2. There are two styles in those cases: placing opening curly brace at the same line and on the new line (which is most likely to be used in your code).
3. You can just place declarations and the code in the "take" method of the "license" class to the "main" function.
4. You did not really use cstdio and string.h libraries, so you can remove their declarations.
5. There is a line `floor(c)` which makes no sense; if you really want to use it, you should change `c = (i) / agent` to `c = floor(i / agent)`.
6. As you can see from my change in point 5, parentheses around i are not necessary.
7. You can try removing comments as you finish your work on this code (although, it is a bad practice if there is a chance someone else will read your code with learning purposes or you will improve it later in time).
8. If there is only one statement, you can omit curly braces in some cases.
[P. S.]
It would be better if you post such questions to the Post Feed as it seems open-ended.
+ 2
Thanks mate ,
about your point 2 - actually I wrote this code in codeblocks ide , so I copied from there and pasted here and messed up the structure here !!
About point 6 the parentheses around I is actually
( i + 1) , but it didn't worked so I removed +1 but forgotten to remove that parentheses
I really appreciate your detailed answer , thank you very much !! I'll take care of your points
0
myname = input()
num_agents = int(input())
other_names = list(input().split())
other_names.append(myname)
other_names.sort()
ind_myname = other_names.index(myname)+1
print('20' if ind_myname <=num_agents else (ind_myname-num_agents)*20+20)
- 3
hhh