fork(5) download
  1. import java.io.*;
  2. import java.math.*;
  3. import java.util.*;
  4.  
  5. public class RR
  6. {
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. int ntest = sc.nextInt();
  10.  
  11. for(int test = 1; test <= ntest; ++test) {
  12. String s = sc.next();
  13. if (s.charAt(0) == '.') s = "0" + s;
  14.  
  15. if (s.indexOf('.') < 0) {
  16. s = s + ".0";
  17. }
  18. if (s.indexOf('(') < 0) {
  19. s = s + "(0)";
  20. }
  21.  
  22. Fraction res = new Fraction();
  23. String a = s.substring(0, s.indexOf('.'));
  24.  
  25. res = new Fraction(new BigInteger(a));
  26.  
  27. String b = s.substring(s.indexOf('.') + 1, s.indexOf('('));
  28. String bb = b;
  29. if (b.length() == 0) bb = "0";
  30.  
  31. res = res.add(new Fraction(new BigInteger(bb), BigInteger.valueOf(10).pow(bb.length())));
  32.  
  33. String c = s.substring(s.indexOf('(') + 1, s.indexOf(')'));
  34. res = res.add(new Fraction(
  35. new BigInteger(c),
  36. BigInteger.valueOf(10).pow(c.length()).subtract(BigInteger.ONE)
  37. .multiply(BigInteger.valueOf(10).pow(b.length()))
  38. ));
  39.  
  40. System.out.println("Case #" + test + ": " + res);
  41. }
  42. }
  43. }
  44.  
  45. class Fraction
  46. {
  47. BigInteger tu, mau;
  48.  
  49. Fraction() {
  50. tu = BigInteger.ZERO;
  51. mau = BigInteger.ONE;
  52. }
  53.  
  54. Fraction(BigInteger tu, BigInteger mau) {
  55. this.tu = tu;
  56. this.mau = mau;
  57.  
  58. if (tu.equals(BigInteger.ZERO)) {
  59. this.mau = BigInteger.ONE;
  60. } else {
  61. BigInteger g = tu.gcd(mau);
  62.  
  63. this.tu = this.tu.divide(g);
  64. this.mau = this.mau.divide(g);
  65. }
  66. }
  67.  
  68. Fraction(BigInteger a) {
  69. this.tu = a;
  70. this.mau = BigInteger.ONE;
  71. }
  72.  
  73. public String toString() {
  74. return tu + "/" + mau;
  75. }
  76.  
  77. Fraction add(Fraction a) {
  78. return new Fraction(tu.multiply(a.mau).add(a.tu.multiply(mau)), a.mau.multiply(mau));
  79. }
  80. }
  81.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
0.125
0.(142857)
0.1(6)
.2
compilation info
Main.java:5: error: class RR is public, should be declared in a file named RR.java
public class RR
       ^
1 error
stdout
Standard output is empty