コード例 #1
0
ファイル: Judge.java プロジェクト: rgrig/homework-eval
 public boolean ok(String out, String reference) {
   // log.fine("out1: " + a);
   // log.fine("out2: " + b);
   Scanner sa = new Scanner(out);
   Scanner sb = new Scanner(reference);
   while (sa.hasNext() && sb.hasNext()) {
     if (sa.hasNextDouble() || sb.hasNextDouble()) {
       if (!sa.hasNextDouble() || !sb.hasNextDouble()) return true;
       double da = sa.nextDouble();
       double db = sb.nextDouble();
       double d_abs = Math.abs(da - db);
       double d_rel = d_abs / Math.abs(db);
       if (!(d_abs < EPS || d_rel < EPS)) {
         log.fine("NOK, " + da + " too far from " + db);
         return false;
       }
     } else {
       String xa = sa.next();
       String xb = sb.next();
       if (!xa.equals(xb)) {
         log.fine("NOK, " + xa + " != " + xb);
         return false;
       }
     }
   }
   if (sa.hasNext() || sb.hasNext()) {
     log.fine("NOK: different number of tokens.");
     return false;
   }
   return true;
 }
コード例 #2
0
ファイル: Exchange.java プロジェクト: pafennell/Java_Part1
  public static void main(String[] args) {
    double rate, pounds, euro;
    String rateStr;

    Scanner input = new Scanner(System.in);

    System.out.print("Please enter the current GB exchange rate: ");
    rate = input.nextDouble();

    System.out.print("\nPlease enter the amount in Pounds you want to convert: ");
    pounds = input.nextDouble();

    if (pounds == 0) {
      System.out.print("\nThank you for using Currency Convertor...Goodbye\n\n");
    }

    while (pounds != 0) {
      System.out.printf(
          "\nThe exchange rate is "
              + rate
              + " The amount of pounds to be converted "
              + pounds
              + "\nThe euro equilavent is €%.2f",
          pounds * rate);

      System.out.print("\n\nPlease enter the amount in Pounds you want to convert: ");
      pounds = input.nextDouble();

      if (pounds == 0) {
        System.out.print("\nThank you for using Currency Convertor...Goodbye\n\n");
      }
    }
    System.exit(0);
  }
コード例 #3
0
ファイル: gaussianGUI.java プロジェクト: AndriansyahYr/kuliah
 public CartesianPanel() {
   double data[];
   Scanner in = new Scanner(System.in);
   int rangeAtas[];
   int rangeBawah[];
   xCoordNumbers = in.nextInt();
   int variabelLinguistik = in.nextInt();
   std = new double[variabelLinguistik];
   sig = new int[variabelLinguistik];
   nilaiAwal = new int[variabelLinguistik];
   nilaiAkhir = new int[variabelLinguistik];
   int temp = 0;
   while (temp < variabelLinguistik) {
     int n = in.nextInt();
     data = new double[n];
     int t = 0;
     while (t < n) {
       data[t] = in.nextDouble();
       t++;
     }
     nilaiAwal[temp] = in.nextInt();
     nilaiAkhir[temp] = in.nextInt();
     std[temp] = findSTDEV(data);
     sig[temp] = (int) (nilaiAkhir[temp] + nilaiAwal[temp]) / 2;
     // System.out.println(nilaiAwal[temp]+" "+nilaiAkhir[temp]+" "+std[temp]+" "+sig[temp]);
     temp++;
   }
   this.alfa = in.nextDouble();
   // this.alfa = alfa;
   // this.xCoordNumbers = nilaiAkhir[temp-1];
   // this.nilaiAwal = rangeAtas;
   // System.out.println(alfa);
   this.jumlahGrafik = variabelLinguistik;
 }
コード例 #4
0
ファイル: HW1_Question6.java プロジェクト: Adempus/CISC3150
  public static void main(String[] args) {
    Scanner scanRadius = new Scanner(System.in);
    Scanner scanCenter = new Scanner(System.in);
    Point2D centerA = new Point2D.Double();
    Point2D centerB = new Point2D.Double();
    double x, y, radiusA = 0, radiusB = 0;

    for (char i = 'A'; i <= 'B'; i++) {
      System.out.print("\nCircle " + i);
      System.out.print("\nEnter center cordinates:" + "\n(x): ");
      x = scanCenter.nextDouble();
      System.out.print("(y): ");
      y = scanCenter.nextDouble();

      System.out.print("Enter radius: ");
      if (i == 'A') {
        radiusA = scanCenter.nextDouble();
        centerA.setLocation(x, y);
      } else if (i == 'B') {
        radiusB = scanCenter.nextDouble();
        centerB.setLocation(x, y);
      }
    }
    scanRadius.close();
    scanCenter.close();

    double distance = distance(centerA, centerB);

    if (distance == (radiusA + radiusB)) System.out.println("\nThe two circles are touching");
    else if ((distance < Math.abs(radiusA - radiusB)))
      System.out.println("\nOne circle encloses another");
    else if (distance < (radiusA + radiusB)) System.out.println("\nThe two circles overlap");
    else if (distance > (radiusA + radiusB)) System.out.println("\nThe two circles are separate");
  }
コード例 #5
0
ファイル: lab3.java プロジェクト: armandodollia/Java101
  public static void main(String[] args) throws FileNotFoundException {
    Scanner inFile = new Scanner(new FileReader("Lab3_input.txt"));
    PrintWriter outFile = new PrintWriter("Lab3_Exercise_output.txt");

    // Declare variables
    String lastName, firstName;
    double salary, pctRaise, salaryFinal;

    // set up while loop
    while (inFile.hasNext()) // condition checks to see if there is anything in the input file
    {
      // Read information from input file
      lastName = inFile.next();
      firstName = inFile.next();
      salary = inFile.nextDouble();
      pctRaise = inFile.nextDouble();

      // Calculate final salary
      salaryFinal = salary + (salary * pctRaise / 100);

      // Write file
      outFile.printf("%s %s %.2f%n", lastName, firstName, salaryFinal);
    }

    // Close input/output methods
    outFile.close();
    inFile.close();
  }
コード例 #6
0
ファイル: bank.java プロジェクト: maenk/Java
 static void Add_customer() throws MaxCustomerException {
   if (count < 10) {
     Scanner sc = new Scanner(System.in);
     System.out.println("enter the name of the customer");
     n = sc.nextLine();
     ac_num = sc.nextDouble();
     bal = sc.nextDouble();
     c[count++] = new customer(n, ac_num, bal);
   } else throw new MaxCustomerException();
 }
コード例 #7
0
ファイル: E4.java プロジェクト: hiroshi-cl/wakaba
  void run() {
    Scanner sc = new Scanner(System.in);
    int oo = sc.nextInt();
    for (int o = 1; o <= oo; o++) {
      que = new PriorityQueue<E>();
      int n = sc.nextInt();
      tank = new Tank();
      count = 0;
      int[] h = new int[n + 3], b = new int[n + 3];
      h[0] = 100;
      b[0] = 0;
      h[n + 1] = 50;
      b[n + 1] = 100;
      h[n + 2] = 50;
      b[n + 2] = INF;
      for (int i = 1; i <= n; i++) {
        b[i] = sc.nextInt();
        h[i] = sc.nextInt();
      }
      n += 3;
      for (int i = 1; i < n; i++) {
        tank.bs.add(new Box(b[i - 1], b[i], h[i - 1], h[i], 0, 0));
      }
      int m = sc.nextInt();
      for (int i = 0; i < m; i++) {
        int f = sc.nextInt();
        double a = sc.nextDouble() / 30;
        for (Box box : tank.bs) {
          if (box.b1 < f && f < box.b2) box.f += a;
        }
      }
      debug(tank.bs);

      int l = sc.nextInt();
      res = new double[l];
      for (int i = 0; i < l; i++) {
        que.offer(new W(sc.nextInt(), sc.nextDouble(), i));
      }
      que.offer(tank.nextEvent());
      debug(que.size());
      while (!que.isEmpty()) {
        if (res[0] < 0) System.exit(1);
        que.poll().go();
        debug(que.peek().time());
        debug(tank.bs);
        debug(res);
        debug();
        if (count == l) break;
      }
      for (double r : res) {
        System.out.println(r);
      }
    }
  }
コード例 #8
0
  public static Matrix scanMatrix() { // 输入矩阵
    int i, j;
    Matrix matrix = new Matrix();
    Scanner scanner = new Scanner(System.in);

    matrix.setLine(scanner.nextInt());
    matrix.setRow(scanner.nextInt());
    matrix.setAccuracy(scanner.nextDouble());
    for (i = 0; i < matrix.getLine(); i++) {
      for (j = 0; j < matrix.getRow(); j++) matrix.setElement(i, j, scanner.nextDouble());
    }
    return matrix;
  }
コード例 #9
0
ファイル: TableLoader.java プロジェクト: TheAndyRoid/urbansim
  /**
   * Loads into a double[][] a plain text file of numbers, with newlines dividing the numbers into
   * rows and tabs or spaces delimiting columns. The Y dimension is not flipped.
   */
  public static double[][] loadTextFile(InputStream stream) throws IOException {
    Scanner scan = new Scanner(stream);

    ArrayList rows = new ArrayList();
    int width = -1;

    while (scan.hasNextLine()) {
      String srow = scan.nextLine().trim();
      if (srow.length() > 0) {
        int w = 0;
        if (width == -1) // first time compute width
        {
          ArrayList firstRow = new ArrayList();
          Scanner rowScan = new Scanner(new StringReader(srow));
          while (rowScan.hasNextDouble()) {
            firstRow.add(new Double(rowScan.nextDouble())); // ugh, boxed
            w++;
          }
          width = w;
          double[] row = new double[width];
          for (int i = 0; i < width; i++) row[i] = ((Double) (firstRow.get(i))).doubleValue();
          rows.add(row);
        } else {
          double[] row = new double[width];
          Scanner rowScan = new Scanner(new StringReader(srow));
          while (rowScan.hasNextDouble()) {
            if (w == width) // uh oh
            throw new IOException("Row lengths do not match in text file");
            row[w] = rowScan.nextDouble();
            w++;
          }
          if (w < width) // uh oh
          throw new IOException("Row lengths do not match in text file");
          rows.add(row);
        }
      }
    }

    if (width == -1) // got nothing
    return new double[0][0];

    double[][] fieldTransposed = new double[rows.size()][];
    for (int i = 0; i < rows.size(); i++) fieldTransposed[i] = ((double[]) (rows.get(i)));

    // now transpose because we have width first
    double[][] field = new double[width][fieldTransposed.length];
    for (int i = 0; i < field.length; i++)
      for (int j = 0; j < field[i].length; j++) field[i][j] = fieldTransposed[j][i];

    return field;
  }
コード例 #10
0
  public static void main(String[] args) throws IOException {

    Scanner sc = new Scanner(new File("B.in"));

    int cases = 0;
    while (true) {
      int B = sc.nextInt();
      int C = sc.nextInt();
      int R = sc.nextInt();
      int Q = sc.nextInt();
      if (B + C + R + Q == 0) break;
      cases++;

      Point2D.Double[] BTS = new Point2D.Double[B];
      Point2D.Double[] cities = new Point2D.Double[C];

      int[][] edges = new int[C][C];
      for (int i = 0; i < C; i++) Arrays.fill(edges[i], -1);

      for (int i = 0; i < B; i++) {
        BTS[i] = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
      }

      for (int i = 0; i < C; i++) {
        cities[i] = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
      }

      for (int i = 0; i < R; i++) {
        int src = sc.nextInt() - 1;
        int dst = sc.nextInt() - 1;
        edges[src][dst] = edgesBetween(BTS, cities, src, dst);
        edges[dst][src] = edges[src][dst];
      }
      /*
      for (int i = 0; i < C; i++) {
      	for (int j = 0; j < C; j++) {
      		System.out.print(edges[i][j] + " ");
      	}
      	System.out.println();
      }
      */
      System.out.println("Case " + cases + ":");
      for (int i = 0; i < Q; i++) {
        int src = sc.nextInt() - 1;
        int dst = sc.nextInt() - 1;
        int ans = dijk(edges, src, dst);
        if (ans == -1) System.out.println("Impossible");
        else System.out.println(ans);
      }
    }
  }
コード例 #11
0
ファイル: UVa11817.java プロジェクト: ABHINAVKR/ACM
 public static void main(String[] args) {
   Scanner scan = new Scanner(System.in);
   int TC = scan.nextInt();
   while (TC-- > 0) {
     double lat1 = scan.nextDouble();
     double lon1 = scan.nextDouble();
     double lat2 = scan.nextDouble();
     double lon2 = scan.nextDouble();
     System.out.printf(
         "%.0f\n",
         gcDistance(lat1, lon1, lat2, lon2, EARTH_RAD)
             - EucledianDistance(lat1, lon1, lat2, lon2, EARTH_RAD));
   }
 }
コード例 #12
0
ファイル: EightQueens.java プロジェクト: azh10/cs
  public static void main(String[] args) {
    System.out.println("Hello World!");

    Scanner input = new Scanner(System.in);

    System.out.print("Enter a number: ");
    double number1 = input.nextDouble();

    System.out.print("Enter second number: ");
    double number2 = input.nextDouble();

    double product = number1 * number2;
    System.out.printf("The product of both numbers is: %f", product);
  }
コード例 #13
0
  protected static ArrayList<Position> readReferencePositions(String filePath)
      throws FileNotFoundException {
    ArrayList<Position> positions = new ArrayList<Position>();
    Scanner scanner = new Scanner(new File(filePath));

    while (scanner.hasNextDouble()) {
      double lat = scanner.nextDouble();
      double lon = scanner.nextDouble();
      double elevation = scanner.nextDouble();
      positions.add(Position.fromDegrees(lat, lon, elevation));
    }

    return positions;
  }
コード例 #14
0
  public static void main(String[] args) {
    int i = 4;
    double d = 4.0;
    String s = "HackerRank ";

    Scanner scan = new Scanner(System.in);

    /* Declare second integer, double, and String variables. */
    int j;
    double e;
    String t;
    /* Read and save an integer, double, and String to your variables.*/
    j = scan.nextInt();
    e = scan.nextDouble();
    scan.nextLine();
    t = scan.nextLine();
    /* Print the sum of both integer variables on a new line. */
    System.out.println(i + j);
    /* Print the sum of the double variables on a new line. */
    System.out.println(d + e);
    /* Concatenate and print the String variables on a new line;
    the 's' variable above should be printed first. */
    System.out.println(s + t);

    scan.close();
  }
コード例 #15
0
  /*
   *  Making sure that the user input is in range
   *  @param1 Scanner object for input
   *  @param2 lowerbound integer
   *  @param3 upperbound integer
   *  @param4 String that specifies for which attribute/field input is for
   *  printing purposes
   *  @param5 ValType enum that specifies whether the primitive value is
   *  an int or double
   *  @param6 boolean that specifies whether the input is an Enum value
   *  @param7 boolean that specifies whether to return the value if out of
   *  range (false) or not (true)
   */
  public static Number makeSureValInRange(
      Scanner input,
      int lowerbound,
      int upperbound,
      String inputFor,
      ValType valType,
      boolean enumeration,
      boolean withinRange) {

    boolean valid = !withinRange;
    Number val = 0;

    while (!valid) {

      System.out.println(inputString(inputFor, null, StringOption.SELECT, enumeration));

      val = valType == ValType.INTEGER ? input.nextInt() : input.nextDouble();

      if (val.intValue() < lowerbound || val.intValue() > upperbound) {
        System.out.println(inputString(inputFor, null, StringOption.INCORRECT, enumeration));
      } else {
        valid = true;
      }
    }
    return val;
  }
コード例 #16
0
 public static void main(String args[]) throws IOException {
   Scanner sf = new Scanner(new File("D:\\IB CS\\temp_Aman\\StudentsScores.in.txt"));
   int maxIndx = -1;
   String text[] = new String[1000];
   while (sf.hasNext()) // this allows the program to assign each line in the text file a variable
   {
     maxIndx++;
     text[maxIndx] = sf.nextLine();
   }
   for (int j = 0; j <= 4; j++) {
     Scanner sc = new Scanner(text[j]);
     String name =
         sc.next(); // this helps identify the Strings, which are the names of students, in each
     // line
     double sum =
         0.0; // it starts the sum and count variables with zero because they change as they move
     // along with the while loop
     int count = 0;
     while (sc.hasNext()) {
       sum = sum + sc.nextDouble(); // this while loop helps find out the number of integers in the
       // line and adds all of these numbers as well
       count = count + 1;
     }
     double avg = sum / count;
     int y = (int) Math.round(avg); // this converts the double variable avg to an integer
     System.out.println(name + "," + " average = " + y);
   }
 }
コード例 #17
0
ファイル: Scores.java プロジェクト: AmelNurkic/BILD-IT-zadaci
 public static void main(String[] args) {
   Scanner input = new Scanner(System.in);
   System.out.println("Enter name of the file: ");
   String a = input.next();
   File file = new File(a);
   if (!file.exists()) {
     System.out.println("The file does not exist");
     System.exit(1);
   }
   double sum = 0;
   double count = 0;
   double avg = 0;
   try {
     Scanner input2 = new Scanner(file);
     while (input2.hasNext()) {
       double score = input2.nextDouble();
       sum = sum + score;
       count++;
     }
   } catch (Exception e) {
     System.out.println("Error!");
   }
   avg = sum / count;
   System.out.println("Total scores: " + count);
   System.out.println("Sum of all scores: " + sum);
   System.out.println("Average of all scores: " + avg);
   input.close();
 }
コード例 #18
0
  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    System.out.print("Introduce el número de empleados: ");
    int empleados = scan.nextInt();

    int num = 1;
    int salarioAlto = 0, salarioBajo = 0;
    double importe = 0;

    while (num <= empleados) {
      System.out.print("Introduzca el salario del empleado " + num + ": ");
      double salario = scan.nextDouble();

      importe += salario;

      if (salario >= 100 && salario < 300) {
        salarioBajo++;
      } else {
        salarioAlto++;
      }

      num++;
    }

    System.out.println("Hay " + salarioBajo + " personas que cobran entre $100 y $300.");
    System.out.println("Hay " + salarioAlto + " personas que cobran más de $300.");
    System.out.println("El importe de los sueldos al personal es de: $" + importe);
  }
コード例 #19
0
ファイル: BCELTest.java プロジェクト: TheDarkestDay/compilers
  public static void main(String[] args) {
    double x = greet(2, 3.4);
    HashMap<String, Double> map = new HashMap<String, Double>();
    HashMap<String, String> mapS = new HashMap<String, String>();
    mapS.put("Test", "Bleh");
    map.put("Hello", 2.1 * 4 + 1 - x);
    System.out.println(map.get("Hello") * 5);
    System.out.println(map.get("Hello"));
    int g = 22;
    int z = 4;
    int v = 8;
    int t = 10;
    int[] arr = new int[10];
    int[] arr2 = new int[25];
    double[] arrDbl = new double[21];
    String[] arrStr = new String[12];
    arr[1] = 15;
    double w = 1.5 * arr[1];
    arrDbl[1] = 2.1;
    arrStr[1] = "Blah";
    String word = "Haha";
    System.out.println(6 + x * 33.4 + CONST);
    System.out.println("Hello, world!");
    while (z > 20 || z < 100) {
      z = z + 1;
    }
    System.out.println("Hello, world!");
    System.out.println(CONST);

    g = scanner.nextInt();
    word = scanner.next();
    arrDbl[1] = scanner.nextDouble();
  }
コード例 #20
0
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int test = scan.nextInt();
		double limit;
		while (test-- > 0) {
			limit = scan.nextDouble();
			n = scan.nextInt();
			V = 0;
			mm = new int[n];
			pp = new float[n];
			for (int i = 0; i < n; i++) {
				mm[i] = scan.nextInt();
				pp[i] = scan.nextFloat();
				V += mm[i];
			}
			dp = new float[V + 1];
			Arrays.fill(dp, 0);
			dp[0] = 1;
			for (int i = 0; i < n; i++)
				ZeroPack(mm[i], 1 - pp[i]);

			for (int i = V; i >= 0; i--)
				if (dp[i] > 1 - limit) {
					out.println(i);
					break;
				}

		}
		out.flush();
		out.close();
	}
コード例 #21
0
ファイル: bank.java プロジェクト: maenk/Java
  static void Deposit() throws InvalidDepositException {
    int i = 0, flag = 0;
    double amount;
    System.out.println("enter your accnt num");
    Scanner sc = new Scanner(System.in);
    ac_num = sc.nextDouble();
    System.out.println("enter the ammont u want to deposit");
    amount = sc.nextDouble();

    for (i = 0; i < 10; i++) {
      if (ac_num == c[i].account_num) flag = 1;
    }
    if (flag == 1) {
      if (c[i].bal > amount) System.out.println(" can be withdrawn");
      else throw InsufficientFundException();
    }
  }
コード例 #22
0
ファイル: Bravo.java プロジェクト: cohadar/gcj-practice
 public static Bravo load(Scanner scanner) {
   int nn = scanner.nextInt();
   assert 1 <= nn && nn <= 100 : "out of range, nn: " + nn;
   double vv = scanner.nextDouble();
   assert 1e-4 <= vv && vv <= 1e4 : "out of range, vv: " + vv;
   double xx = scanner.nextDouble();
   assert 0.1 <= xx && xx <= 99.9 : "out of range, xx: " + xx;
   double[] R = new double[nn];
   double[] C = new double[nn];
   for (int i = 0; i < nn; i++) {
     R[i] = scanner.nextDouble();
     C[i] = scanner.nextDouble();
     assert 1e-4 <= R[i] && R[i] <= 1e4 : "out of range, R[i]: " + R[i];
     assert 0.1 <= C[i] && C[i] <= 99.9 : "out of range, C[i]: " + C[i];
   }
   return new Bravo(nn, vv, xx, R, C);
 }
コード例 #23
0
ファイル: Arctic.java プロジェクト: reallhy/reallhy
 public static void main(String... args) {
   System.setIn(
       new ByteArrayInputStream(
           "2\n5\n0 0\n1 0\n1 1\n1 2\n0 2\n6\n1.0 1.0\n30.91 8\n4.0 7.64\n21.12 6.0\n11.39 3.0\n5.31 11.0"
               .getBytes()));
   Scanner scanner = new Scanner(System.in);
   int t = scanner.nextInt();
   for (int i = 0; i < t; i++) {
     int n = scanner.nextInt();
     Coord[] towers = new Coord[n];
     for (int j = 0; j < n; j++) {
       towers[j] = new Coord(scanner.nextDouble(), scanner.nextDouble());
     }
     Arctic arctic = new Arctic(towers);
     arctic.minPower(0, new boolean[n], new double[n - 1]);
     System.out.printf("%.2f\n", arctic.min);
   }
 }
コード例 #24
0
ファイル: Hypot.java プロジェクト: DenisKipchakbaev/Schildt
  public static void main(String args[]) {
    Scanner s = new Scanner(System.in);
    double side1, side2;
    double hypot;
    System.out.print("Enter side1 value: ");
    side1 = s.nextDouble();
    System.out.println();
    System.out.print("Enter side2 value: ");
    side2 = s.nextDouble();
    System.out.println();

    /* Notice how sqrt() and pow() must be qualified by
    their class name, which is Math. */
    hypot = Math.sqrt(Math.pow(side1, 2) + Math.pow(side2, 2));

    System.out.println(
        "Given sides of lengths " + side1 + " and " + side2 + " the hypotenuse is " + hypot);
  }
コード例 #25
0
ファイル: 2651.java プロジェクト: sdecoder/pku-online-judge
 public static void main(String[] str) {
   Scanner sc = new Scanner(System.in);
   while (sc.hasNext()) {
     int n = sc.nextInt();
     t = sc.nextDouble();
     if (n == 0) break;
     System.out.printf("%.3f\n", e(1, n));
   }
 }
コード例 #26
0
  public static void main(String[] args) throws IOException {

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    while (true) {
      int n = sc.nextInt();
      if (n == 0) break;
      ArrayList<LineSegment> segments = new ArrayList<LineSegment>(1000);

      for (int i = 0; i < n; i++) {
        LineSegment cur =
            new LineSegment(
                new Point(sc.nextDouble(), sc.nextDouble()),
                new Point(sc.nextDouble(), sc.nextDouble()),
                i + 1);
        Line l = new Line(cur.left, cur.right);
        ArrayList<LineSegment> tmp = new ArrayList<LineSegment>(1000);
        for (int j = 0, size = segments.size(); j < size; j++) {
          LineSegment nxt = segments.get(j);
          Line ll = new Line(nxt.left, nxt.right);
          boolean top = true;
          if (l.parallel(ll)) {
            if (l.same(ll))
              if (nxt.left.between(cur.left, cur.right)
                  || nxt.right.between(cur.left, cur.right)
                  || cur.left.between(nxt.left, nxt.right)
                  || cur.right.between(nxt.left, nxt.right)) top = false;
          } else {
            Point c = l.intersect(ll);
            if (c.between(cur.left, cur.right) && c.between(nxt.left, nxt.right)) top = false;
          }
          if (top) tmp.add(nxt);
        }
        segments = tmp;
        segments.add(cur);
      }

      out.print("Top sticks:");
      for (int i = 0, size = segments.size(); i < size - 1; i++)
        out.printf(" %d,", segments.get(i).idx);
      out.printf(" %d.\n", segments.get(segments.size() - 1).idx);
    }
    out.flush();
  }
コード例 #27
0
ファイル: Main.java プロジェクト: khankuan/UVA
  public static void main(String[] args) {
    Scanner scans = new Scanner(System.in);
    int test = 1;
    while (true) {
      int V = scans.nextInt();
      int E = scans.nextInt();
      int Q = scans.nextInt();

      if (V == 0 && E == 0 && Q == 0) break;
      scans.nextLine();
      if (test > 1) System.out.println("");

      double[] p = new double[V];
      double[] q = new double[V];
      TreeMap<String, Integer> names = new TreeMap<String, Integer>();

      for (int i = 0; i < V; i++) {
        String n = scans.next();
        p[i] = scans.nextDouble();
        q[i] = scans.nextDouble();
        scans.nextLine();
        names.put(n, i);
      }

      long[][] APSP = new long[V][V];
      for (int i = 0; i < V; i++) Arrays.fill(APSP[i], INF);

      for (int i = 0; i < E; i++) {
        String one = scans.next();
        String two = scans.next();
        scans.nextLine();
        int onei = names.get(one);
        int twoi = names.get(two);
        APSP[onei][twoi] =
            gcDistance(
                p[onei], q[onei], // 3D version
                p[twoi], q[twoi], 6378);
      }

      for (int k = 0; k < V; k++)
        for (int i = 0; i < V; i++)
          for (int j = 0; j < V; j++) APSP[i][j] = Math.min(APSP[i][j], APSP[i][k] + APSP[k][j]);

      System.out.println("Case #" + test);
      for (int i = 0; i < Q; i++) {
        String one = scans.next();
        String two = scans.next();
        scans.nextLine();
        int onei = names.get(one);
        int twoi = names.get(two);
        if (APSP[onei][twoi] != INF) System.out.println((APSP[onei][twoi]) + " km");
        else System.out.println("no route exists");
      }
      test++;
    }
  }
コード例 #28
0
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    double y = sc.nextDouble();
    String s = sc.nextLine();

    System.out.println("String: " + s);
    System.out.println("Double: " + y);
    System.out.println("Int: " + x);
  }
コード例 #29
0
ファイル: T01n03.java プロジェクト: KrbAlmryde/Homework
  public static void main(String[] args) {
    double x1, y1; // coordinates of the first point
    double x2, y2; // coordinates of the second point
    double distance; // distance between the two points
    double distanceForDisplay; // rounded to two decimal places

    Scanner keyboard = new Scanner(System.in); // still magic!

    // Gather the coordinates of the two points

    System.out.print("Enter the x-coordinate of the first point : ");
    x1 = keyboard.nextDouble();

    System.out.print("Enter the y-coordinate of the first point : ");
    y1 = keyboard.nextDouble();

    System.out.print("Enter the x-coordinate of the second point : ");
    x2 = keyboard.nextDouble();

    System.out.print("Enter the y-coordinate of the second point : ");
    y2 = keyboard.nextDouble();

    // Compute the distance between the points, and
    // round the result to two decimal places.

    distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
    distanceForDisplay = Math.round(distance * 100) / 100D;

    System.out.println(
        "\nThe distance from ("
            + x1
            + ","
            + y1
            + ") "
            + "to ("
            + x2
            + ","
            + y2
            + ") "
            + "is "
            + distanceForDisplay
            + " units.");
  }
コード例 #30
0
ファイル: Exercise_2.java プロジェクト: fredz0003/MalikJava
  public static void main(String[] args) {
    double height;
    double radius;

    System.out.print("Enter the height of the cylinder: ");
    height = console.nextDouble();

    System.out.println();

    System.out.print("Enter the radius of the base of the " + " cylinder: ");
    radius = console.nextDouble();

    System.out.println("Volume of the cylinder = " + PI * Math.pow(radius, 2.0) * height);

    System.out.println();

    System.out.println(
        "Surface area: " + ((2 * PI * Math.pow(radius, 2.0)) + (2 * PI * radius * height)));
  }