示例#1
0
 public static void main(String[] args) throws Exception {
   Scanner s = new Scanner(new FileReader("pb.in"));
   while (s.hasNext()) {
     String line = s.nextLine();
     String[] rep = line.split("\\(");
     String[] nonrep = (rep[0] + "0").split("\\.");
     long num1 = Integer.parseInt(rep[1].substring(0, rep[1].length() - 1));
     String nine = "";
     while (nine.length() != rep[1].length() - 1) nine += "9";
     for (int i = 0; i < nonrep[1].length() - 1; i++) nine += "0";
     String ten = "";
     while (nonrep[1].length() != ten.length()) ten += "0";
     ten = "1" + ten;
     String nr = nonrep[0] + nonrep[1];
     long den1 = Long.parseLong(nine);
     long den2 = Long.parseLong(ten);
     long num2 = Long.parseLong(nr);
     long num = num1 * den2 + num2 * den1;
     long den = den1 * den2;
     long gcd = new BigInteger("" + num).gcd(new BigInteger("" + den)).longValue();
     num /= gcd;
     den /= gcd;
     System.out.println(line + " = " + num + " / " + den);
   }
 }
  public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFBamMssCFBindInt64DefMinValue.expandBody() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFBamInt64DefObj) {
      Long minValue = ((ICFBamInt64DefObj) genDef).getOptionalMinValue();
      if (minValue == null) {
        ret = null;
      } else {
        ret = minValue.toString();
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), "expandBody", "genContext.getGenDef()", genDef, "ICFBamInt64DefObj");
    }

    return (ret);
  }
  public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFBamMssCFBindUuidGenDispenserId.expandBody() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFBamUuidGenObj) {
      Long dispenserId = ((ICFBamUuidGenObj) genDef).getOptionalDispenserId();
      if (dispenserId == null) {
        ret = null;
      } else {
        ret = dispenserId.toString();
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), "expandBody", "genContext.getGenDef()", genDef, "ICFBamUuidGenObj");
    }

    return (ret);
  }
示例#4
0
文件: DataType.java 项目: inexas/oak
 public static long getLong(Object value)
     throws NullValueException, TypeMismatchException, OverflowException {
   final Long result;
   if (value == null) {
     throw new NullValueException();
   }
   result = convert(value, Long.class);
   return result.longValue();
 }
示例#5
0
 /**
  * @param file
  * @return
  * @throws IOException
  */
 static long readUnsignedLong(final ERandomAccessFile file) throws IOException {
   final long result = file.readLongE();
   if (result < 0) {
     throw new IOException(
         "Maximal file offset is "
             + Long.toHexString(Long.MAX_VALUE)
             + " given offset is "
             + Long.toHexString(result));
   }
   return result;
 }
 public String toString() {
   String ret =
       "<CFFreeSwitchPbxIvrMenuEntryByMenuIdIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredMenuId="
           + "\""
           + Long.toString(getRequiredMenuId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFCrmContactURLPKey"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredContactURLId="
           + "\""
           + Long.toString(getRequiredContactURLId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFBamScopePKey"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredId="
           + "\""
           + Long.toString(getRequiredId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFBamPopDepByRelationIdx"
           + " RequiredRelationTenantId="
           + "\""
           + Long.toString(getRequiredRelationTenantId())
           + "\""
           + " RequiredRelationId="
           + "\""
           + Long.toString(getRequiredRelationId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFBamClearTopDepByContTblIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredContTableId="
           + "\""
           + Long.toString(getRequiredContTableId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFDbTestValueByScopeIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredScopeId="
           + "\""
           + Long.toString(getRequiredScopeId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFCrmMemoTagByTagIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredTagId="
           + "\""
           + Long.toString(getRequiredTagId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFDbTestBoolTypeBySchemaIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredSchemaDefId="
           + "\""
           + Long.toString(getRequiredSchemaDefId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFBamTimeColByTableIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredTableId="
           + "\""
           + Long.toString(getRequiredTableId())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFAsteriskClusterId64Gen"
           + " RequiredId="
           + "\""
           + Long.toString(getRequiredId())
           + "\""
           + ", SliceId=\""
           + Short.toString(getRequiredSliceId())
           + "\""
           + ", NextId=\""
           + Long.toString(nextId)
           + "\"/>";
   return (ret);
 }
  public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFFreeSwitchMssCFBindFSSFProfileAliasFSSFProfileId.expandBody() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFFreeSwitchFSSFProfileAliasObj) {
      long fSSFProfileId = ((ICFFreeSwitchFSSFProfileAliasObj) genDef).getRequiredFSSFProfileId();
      ret = Long.toString(fSSFProfileId);
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(),
              "expandBody",
              "genContext.getGenDef()",
              genDef,
              "ICFFreeSwitchFSSFProfileAliasObj");
    }

    return (ret);
  }
  public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFDbTestMssCFBindReqMinMaxValueTestUInt32.expandBody() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFDbTestReqMinMaxValueObj) {
      long testUInt32 = ((ICFDbTestReqMinMaxValueObj) genDef).getRequiredTestUInt32();
      ret = Long.toString(testUInt32);
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(),
              "expandBody",
              "genContext.getGenDef()",
              genDef,
              "ICFDbTestReqMinMaxValueObj");
    }

    return (ret);
  }
示例#18
0
  public static void main(String[] args) {
    if (args.length < 5) {
      System.out.println(
          "\n  Usage: java prob.mdp.MDPSim prob_file " + "spudd_vfun trials steps rand_seed\n");
      System.exit(1);
    }

    MDPSim mdpsim = new MDPSim(args[0], args[1]);

    ArrayList vals = null;
    int trials = -1, steps = -1;
    long seed = -1;
    try {
      trials = Integer.parseInt(args[2]);
      steps = Integer.parseInt(args[3]);
      seed = Long.parseLong(args[4]);
      vals = mdpsim.simulate(trials, steps, seed);
    } catch (NumberFormatException nfe) {
      System.out.println(nfe);
      System.exit(1);
    }

    System.out.println("\n Problem:  " + args[0]);
    System.out.println(" VFun:     " + args[1]);
    System.out.println(" Trials:   " + trials);
    System.out.println(" Steps:    " + steps);
    System.out.println(" Seed:     " + seed);
    System.out.println(" Data:     " + PrintList(vals));
    System.out.println(" Average:  " + MDP._df.format(Average(vals)) + "\n");
  }
  public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFBamMssCFBindPopSubDep1ContPopTopDepId.expandBody() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), "expandBody", 1, "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFBamPopSubDep1Obj) {
      long contPopTopDepId = ((ICFBamPopSubDep1Obj) genDef).getRequiredContPopTopDepId();
      ret = Long.toString(contPopTopDepId);
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), "expandBody", "genContext.getGenDef()", genDef, "ICFBamPopSubDep1Obj");
    }

    return (ret);
  }
示例#20
0
 private long[] parse(String[] as) {
   long ans[] = new long[as.length];
   int index = 0;
   for (String cur : as) ans[index++] = Long.parseLong(cur, 2);
   Arrays.sort(ans);
   return ans;
 }
示例#21
0
 public Fraction(BigDecimal original) {
   super();
   double A, C, D, X, Y, M;
   C = original.doubleValue();
   A = C;
   D = C;
   X = 1;
   Y = 0;
   do {
     M = Y;
     Y = X + Y * Math.round(C);
     X = M;
     if (C != Math.round(C)) {
       C = 1 / (C - Math.round(C));
     }
     M = Math.round(D * Y);
   } while (M != MathUtilities.toFix(D * Y, 10));
   if ((Math.abs(M) > 100000) || (Math.abs(Y) > 100000) || (Math.abs(Y) == 1)) {
     this.numerator = original;
     this.denominator = BigInteger.ONE;
   } else {
     this.numerator =
         BigDecimal.valueOf(Math.round((Math.abs(M) / M) * (Math.abs(Y) / Y) * Math.abs(M)));
     this.denominator = new BigInteger(Long.toString(Math.round(Math.abs(Y))));
   }
 }
示例#22
0
 private void getPositions(HttpServletRequest request, Role item) {
   String[] pos = request.getParameterValues("positions");
   item.clearPositions();
   for (int i = 0; i < pos.length; i++) {
     item.addPosition(Long.parseLong(pos[i]));
   }
 }
示例#23
0
 private void getPermissions(HttpServletRequest request, Role item) {
   String[] per = request.getParameterValues("permissions");
   item.clearPermissions();
   for (int i = 0; i < per.length; i++) {
     item.addPermission(Long.parseLong(per[i]));
   }
 }
示例#24
0
 long ipToInteger(String s) {
   String[] t = s.split("\\.");
   long a = Long.parseLong(t[0]);
   long b = Integer.parseInt(t[1]);
   long c = Integer.parseInt(t[2]);
   long d = Integer.parseInt(t[3]);
   return (a << 24) | (b << 16) | (c << 8) | d;
 }
 public String toString() {
   String ret =
       "<CFBamValueHPKey"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredId="
           + "\""
           + Long.toString(getRequiredId())
           + "\""
           + " RequiredRevision=\""
           + Integer.toString(getRequiredRevision())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFFreeSwitchFSSFDialerHPKey"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredFSSFDialerId="
           + "\""
           + Long.toString(getRequiredFSSFDialerId())
           + "\""
           + " RequiredRevision=\""
           + Integer.toString(getRequiredRevision())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFInternetMajorVersionByNameIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredParentProjectId="
           + "\""
           + Long.toString(getRequiredParentProjectId())
           + "\""
           + " RequiredName="
           + "\""
           + CFInternetSchema.xmlEncodeString(getRequiredName())
           + "\""
           + "/>";
   return (ret);
 }
 public String toString() {
   String ret =
       "<CFDbTestTableByUNameIdx"
           + " RequiredTenantId="
           + "\""
           + Long.toString(getRequiredTenantId())
           + "\""
           + " RequiredSchemaDefId="
           + "\""
           + Long.toString(getRequiredSchemaDefId())
           + "\""
           + " RequiredName="
           + "\""
           + CFDbTestSchema.xmlEncodeString(getRequiredName())
           + "\""
           + "/>";
   return (ret);
 }
示例#29
0
文件: DataType.java 项目: inexas/oak
  /**
   * Given the parsing context and what numerical data type is expected convert a string to the
   * correct type. Note no attempt is made to let the magnitude of the number influence our choice.
   *
   * @param string The string to convert to a number. E.g. "123.3e2". If it contains a '.' or an 'e'
   *     then the type must either be f or F.
   * @param requiredType Either z, Z, f, F or any.
   * @param tb The source. The cursor will be at the end of the number but any type specifier will
   *     not have been consumed. If there is one then we'll eat it.
   * @return The derived type.
   * @throws ParsingException If there is a clash of types.
   */
  private static Object deriveType(String string, DataType requiredType, Text t, int radix) {
    final Object result;

    // Figure out the correct type...
    final DataType derivedType;
    if (t.isEof()) {
      if (requiredType == DataType.any) {
        if (string.indexOf('.') >= 0 || string.indexOf('e') >= 0) {
          derivedType = DataType.f;
        } else {
          derivedType = DataType.z;
        }
      } else {
        derivedType = requiredType;
      }
    } else {
      final char c = t.peek();
      if (c == 'z' || c == 'Z' || c == 'f' || c == 'F') {
        t.consume(c);
        derivedType = DataType.valueOf(String.valueOf(c));
        if (!(requiredType == DataType.any || requiredType == derivedType)) {
          throw new ParsingException("Incompatible type: " + string + c);
        }
      } else {
        if (requiredType == DataType.any) {
          if (string.indexOf('.') >= 0 || string.indexOf('e') >= 0) {
            derivedType = DataType.f;
          } else {
            derivedType = DataType.z;
          }
        } else {
          derivedType = requiredType;
        }
      }
    }

    switch (derivedType) {
      case z:
        result = new Long(Long.parseLong(string, radix));
        break;
      case Z:
        result = new BigInteger(string, radix);
        break;
      case f:
        result = new Double(string);
        break;
      case F:
        result = new BigDecimal(string);
        break;
        // $CASES-OMITTED$
      default:
        throw new UnexpectedException("toType: " + derivedType);
    }

    return result;
  }
示例#30
0
 /**
  * Get the long value associated with an index.
  *
  * @param index The index must be between 0 and length() - 1.
  * @return The value.
  * @throws JSONException If the key is not found or if the value cannot be converted to a number.
  */
 public long getLong(int index) throws JSONException {
   Object object = this.get(index);
   try {
     return object instanceof Number
         ? ((Number) object).longValue()
         : Long.parseLong((String) object);
   } catch (Exception e) {
     throw new JSONException("JSONArray[" + index + "] is not a number.");
   }
 }