public static void main(String[] args) {
    BufferedReader in;

    try {
      in =
          new BufferedReader(
              new FileReader(
                  "/Users/rahulkhairwar/Documents/IntelliJ IDEA Workspace/Competitive "
                      + "Programming/src/com/google/codejam16/qualificationround/inputB.txt"));

      OutputWriter out = new OutputWriter(System.out);
      Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 28);

      thread.start();

      try {
        thread.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      out.flush();

      in.close();
      out.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    int tc = in.nextInt();
    while (tc-- > 0) {
      String a = in.nextString();
      String b = in.nextString();
      int[][] dp = new int[2][b.length() + 1];
      dp[1][0] = 1;
      for (int i = 0; i <= b.length(); i++) {
        dp[0][i] = i;
      }

      for (int i = 1, r = a.length(); i <= r; i++) {
        dp[i % 2][0] = i;
        for (int j = 1, c = b.length(); j <= c; j++) {
          if (a.charAt(i - 1) == b.charAt(j - 1)) {
            dp[i % 2][j] = dp[(i - 1) % 2][j - 1];
          } else {
            dp[i % 2][j] = 1 + min(dp[(i - 1) % 2][j], dp[(i - 1) % 2][j - 1], dp[i % 2][j - 1]);
          }
        }
      }

      out.println(dp[a.length() % 2][b.length()]);
    }

    out.flush();
    out.close();
  }
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    Solver solver = new Solver(in, out);

    solver.solve();
    in.close();
    out.flush();
    out.close();
  }
  public static void main(String[] args) {
    in = new InputReader(System.in);
    out = new OutputWriter(System.out);

    solve();

    out.flush();

    in.close();
    out.close();
  }
Ejemplo n.º 5
0
    public static void main(String[] argv) throws IOException
    {
        Task t;
        boolean home = argv.length > 0 && argv[0].equals("test");
        InputStream inputStream;
        OutputStream outputStream;
        if (home) {
            inputStream = new FileInputStream(Task.filename + ".in");
            outputStream = new FileOutputStream(Task.filename + ".out");
        } else {
            switch (Task.read) {
                case 0:
                    inputStream = new FileInputStream(Task.filename + ".in");
                    outputStream = new FileOutputStream(Task.filename + ".out");
                    break;
                case 1:
                    inputStream = new FileInputStream("input.txt");
                    outputStream = new FileOutputStream("output.txt");
                    break;
                default:
                    inputStream = System.in;
                    outputStream = System.out;
                    break;

            }

        }
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream, home);


        if (home)
            do {
                long time = System.currentTimeMillis();
                t = new Task();
                t.in = in;
                t.out = out;
                t.run();

                out.writeln();
                out.writeln("=====Time:" + (System.currentTimeMillis() - time));
                out.flush();
            } while (in.toNextTest());
        else {
            t = new Task();
            t.in = in;
            t.out = out;
            t.run();
        }

        out.close();

    }
Ejemplo n.º 6
0
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    int tc = in.nextInt();
    while (tc-- > 0) {
      int n = in.nextInt();
      out.println(countTri(n));
    }

    out.flush();
    out.close();
  }
Ejemplo n.º 7
0
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    while (true) {
      int n = in.nextInt();
      if (n == 0) break;
      int c = 0;
      while (n > 1) {
        n /= 2;
        c++;
      }

      out.println(c);
    }
    out.flush();
    out.close();
  }