# Reverse Root Problem. My solution. Need check

Ivan Franko
Ranch Hand
Posts: 46
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.

Campbell Ritchie
Sheriff
Posts: 50674
83
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[]?
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
Sheriff
Posts: 50674
83
Who “accepted” that solution?

Ivan Franko
Ranch Hand
Posts: 46
I uploaded code on http://acm.timus.ru/. On this server code was successfully executed and passed through couple tests. All happened automatically.

Ulf Dittmer
Rancher
Posts: 42968
73
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.

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
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
Sheriff
Posts: 50674
83
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
Sheriff
Posts: 50674
83
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
Yep, It is 10 x18. I don't know how insert superscript in the post message.

Campbell Ritchie
Sheriff
Posts: 50674
83
I didn’t know how to do that myself, but have done some research.

You can try &sup1; (¹), (or ², ³) but I couldn’t seem to get it to work for 8. Try &#x00b2; (or 1, 3) for ² and &#x2070; for ⁰ (or &#x2074 for ⁴ etc). A little more information here.

Campbell Ritchie
Sheriff
Posts: 50674
83
&#x00b9; &#x00b2; &#x00b3; = ¹ ² ³
[added 28th March 2014]In this post, Sudhir Srinivasan points out that \u207f is ⁿ