I was working on some problem in codeforces just for practice and the implementation I came up with is based on using the Math.pow()
method in Java:
import java.io.*;
import java.util.*;
public class TestClass {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
long t = sc.nextLong();
//note that "MyScanner" is a pre-defined class for buffered input
//just to make it easier to call the methods
while (t-- > 0){
String m = sc.next();
long l = m.length(), n = Long.parseLong(m);
out.println(n - Math.pow(10, l-1));
}
out.close();
}
}
I/O example: the input can be too big, that's why I used the long datatype.
Input:
7
1
2
178
20
999999999
9000
987654321
Output:
0
1
78
10
899999999
8000
887654321
but instead I get this:
0.0
1.0
78.0
10.0
8.99999999E8
8000.0
8.87654321E8
as you can see, my solution seems to be correct, but the output was in different form.