• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reverse Root Problem. My solution. Need check

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Condition:


Input
The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB.
Output
For each number Ai from the last one till the first one you should output its square root. Each square root should be printed in a separate line with at least four digits after decimal point.



Sample:


input:
1427 0

876652098643267843
5276538

output:
2297.0716
936297014.1164
0.0000
37.7757



My code below:


Judgement result:
Accepted

So, my first goal was successfully completed - I found solution for this exercise.
but, currently, I think about other point: code quality.
I would like reach high code quality level.

What do you think, this code is ok? Because, I am not sure, that my solution with processing InputStream is really cool.
Could you please suggest any improvements if it is need.
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.
You should not have so much code in the main method; its ideal length is one statement.
Why are you using a Long?
Why are you putting Longs into a List?
Why have you got a byte[]?
Why are you using that dreadful method, System.in .read()?
Where did you get 262144 from? It says not more than 256kB. It does not say exactly 256kB.
Why are you using DecimalFormat rather than the % tags?
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Who “accepted” that solution?
 
Ivan Franko
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I uploaded code on http://acm.timus.ru/. On this server code was successfully executed and passed through couple tests. All happened automatically.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You should not have so much code in the main method; its ideal length is one statement.


Stating this in absolute terms is wrong, IMO - this is hardly an accepted best practice in the industry.

Why are you using that dreadful method, System.in .read()?


In what is clearly a learning exercise, I think there's nothing wrong with using it if the focus of the lesson lies elsewhere.

Why are you using DecimalFormat rather than the % tags?


Choosing one over the other is a matter of preference in my book, not an issue of code quality.
 
Ivan Franko
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why are you using a Long?


Because: digit between 0 ≤ A ≤ 10X18, but Integer.MAX_VALUE=2147483647

Why are you putting Longs into a List?


Because I dont know how much digits came from input string. In this case where can I save any number od digits? In array? But How?

Why have you got a byte[]?


Sorry?
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have given a good reason for the List, but not for the byte[]. If you don’t know what it is for, why don’t you get rid of it?
It said 1018 in the original post, which does not require a long, nor does 10×18. Do you mean 10 to the 18th power? That does require a long.
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ought to learn to read. You haven’t got a byte[]. What a stupid mistake of mine. Sorry about that
 
Ivan Franko
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, It is 10 x18. I don't know how insert superscript in the post message.
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn’t know how to do that myself, but have done some research.

You can try ¹ (¹), (or ², ³) but I couldn’t seem to get it to work for 8. Try ² (or 1, 3) for ² and ⁰ for ⁰ (or &#x2074 for ⁴ etc). A little more information here.
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
¹ ² ³ = ¹ ² ³
[added 28th March 2014]In this post, Sudhir Srinivasan points out that \u207f is ⁿ
 
reply
    Bookmark Topic Watch Topic
  • New Topic