Exemplo n.º 1
0
 public Solution() throws IOException {
   Locale.setDefault(Locale.US);
   in = new BufferedReader(new FileReader("input.txt"));
   out = new PrintWriter("output.txt");
   solve();
   in.close();
   out.close();
 }
Exemplo n.º 2
0
 private long[] nextLongs() throws IOException {
   String s = br.readLine();
   String[] sp = s.split(" ");
   long[] r = new long[sp.length];
   for (int i = 0; i < sp.length; i++) {
     r[i] = parseLong(sp[i]);
   }
   return r;
 }
Exemplo n.º 3
0
 private int[] nextInts() throws IOException {
   String s = br.readLine();
   String[] sp = s.split(" ");
   int[] r = new int[sp.length];
   for (int i = 0; i < sp.length; i++) {
     r[i] = parseInt(sp[i]);
   }
   return r;
 }
Exemplo n.º 4
0
 public String next() {
   while (tokenizer == null || !tokenizer.hasMoreTokens()) {
     try {
       tokenizer = new StringTokenizer(reader.readLine());
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   return tokenizer.nextToken();
 }
Exemplo n.º 5
0
  public void solve() throws Exception {
    String str = in.readLine();
    int n = str.length();

    int t = Integer.parseInt(in.readLine());

    int[][] dp = new int[26][n];

    dp[str.charAt(0) - 'a'][0] = 1;

    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        if (str.charAt(i) == 'a' + j) {
          dp[j][i] = dp[j][i - 1] + 1;
        } else {
          dp[j][i] = dp[j][i - 1];
        }
      }
    }

    while (t-- > 0) {
      st = new StringTokenizer(in.readLine());
      char a = st.nextToken().toCharArray()[0];
      char b = st.nextToken().toCharArray()[0];

      int l = parseInt(st.nextToken()) - 1;
      int r = parseInt(st.nextToken()) - 1;

      int ans = 0;
      for (int i = l; i <= r; i++) {
        if (str.charAt(i) == a) {
          ans += dp[b - 'a'][r] - dp[b - 'a'][i];
        }
      }

      out.println(ans);
    }
  }
Exemplo n.º 6
0
  public boolean loadSourceFile(File file) {
    boolean result = false;

    selectedPath = file.getParent();

    BufferedReader sourceFile = null;

    String directoryPath = file.getParent();
    String sourceName = file.getName();

    int idx = sourceName.lastIndexOf(".");
    fileExt = idx == -1 ? "" : sourceName.substring(idx + 1);
    baseName = idx == -1 ? sourceName.substring(0) : sourceName.substring(0, idx);
    String basePath = directoryPath + File.separator + baseName;

    DataOptions.directoryPath = directoryPath;

    sourcePath = file.getPath();

    AssemblerOptions.sourcePath = sourcePath;
    AssemblerOptions.listingPath = basePath + ".lst";
    AssemblerOptions.objectPath = basePath + ".cd";

    String var = System.getenv("ROPE_MACROS_DIR");
    if (var != null && !var.isEmpty()) {
      File dir = new File(var);
      if (dir.exists() && dir.isDirectory()) {
        AssemblerOptions.macroPath = var;
      } else {
        AssemblerOptions.macroPath = directoryPath;
      }
    } else {
      AssemblerOptions.macroPath = directoryPath;
    }

    DataOptions.inputPath = AssemblerOptions.objectPath;
    DataOptions.outputPath = basePath + ".out";
    DataOptions.readerPath = null;
    DataOptions.punchPath = basePath + ".pch";
    DataOptions.tape1Path = basePath + ".mt1";
    DataOptions.tape2Path = basePath + ".mt2";
    DataOptions.tape3Path = basePath + ".mt3";
    DataOptions.tape4Path = basePath + ".mt4";
    DataOptions.tape5Path = basePath + ".mt5";
    DataOptions.tape6Path = basePath + ".mt6";

    this.setTitle("EDIT: " + sourceName);
    fileText.setText(sourcePath);

    if (dialog == null) {
      dialog = new AssemblerDialog(mainFrame, "Assembler options");

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension dialogSize = dialog.getSize();
      dialog.setLocation(
          (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
    }

    dialog.initialize();

    AssemblerOptions.command = dialog.buildCommand();

    sourceArea.setText(null);

    try {
      sourceFile = new BufferedReader(new FileReader(file));
      String line;

      while ((line = sourceFile.readLine()) != null) {
        sourceArea.append(line + "\n");
      }

      sourceArea.setCaretPosition(0);
      optionsButton.setEnabled(true);
      assembleButton.setEnabled(true);
      saveButton.setEnabled(true);

      setSourceChanged(false);
      undoMgr.discardAllEdits();

      result = true;
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      try {
        if (sourceFile != null) {
          sourceFile.close();
        }
      } catch (IOException ignore) {
      }
    }

    return result;
  }
  private static List<String> importGenomeData(
      File genome_text_file, String target_organism, int sex) throws IOException {

    List<String> temp_genome_data =
        new ArrayList<String>(); // The genome data array that contains the sizes of each chromosome
    // int haploid_number; // Used to determine the size of the first dimension in the
    // temp_genome_data array
    boolean found_target_organism =
        false; // Used to determine what action to take when a new header line in the file is found;
    // close if true, keep reading if false
    boolean end_of_genome = false; // True when the Y chromosome has been dealt with

    // Construct BufferedReader from FileReader; search for header line of target organism and
    // obtain the haploid number then create a two dimensional array, size of the first dimension
    // equals the haploid number, size of second dimension equals two (two chromosomes to form
    // deploid organism)
    // At this point, the next lines correspond to the size of each chromosome so populate the newly
    // created array
    // with this information. Stop reading when no more new lines or when a new header line is found
    BufferedReader genome_file_reader = new BufferedReader(new FileReader(genome_text_file));

    String line = null;
    StringBuilder organism_name;
    while ((line = genome_file_reader.readLine()) != null) {
      String[] split_line = line.split(" ");

      if (split_line[0].equals(">")) // If this is a first header line
      {
        organism_name =
            new StringBuilder()
                .append(split_line[1])
                .append(" ")
                .append(
                    split_line[
                        2]); // Recreate the genus and species of the organism from the strings that
        // were separated during the splitting of the line
        if (organism_name
            .toString()
            .equals(target_organism)) // If this line refers to the organism of interest
        {
          found_target_organism = true;
          haploid_number =
              Integer.parseInt(split_line[4]); // Get the haploid number stored in the header line
        } else {
          found_target_organism = false;
          continue; // This is a header line but it is not the organism of interest
        }
      } else if (found_target_organism
          && !end_of_genome) // This is not a header line and we probably want to import this line
      {
        // boolean autosome = true;
        switch (sex) {
          case 1: // Female
            {
              if (split_line[0].equals("chrX")) {
                temp_genome_data.add(split_line[1] + "," + split_line[1]);
              } else if (split_line[0].equals("chrY")) {
                end_of_genome = true;
              } // Ignore the Y chromosome
              else
                temp_genome_data.add(
                    split_line[1] + "," + split_line[1]); // The current line is an autosome
            }
            break;
          case 2: // Male
            {
              if (split_line[0].equals("chrX")) {
                temp_genome_data.add(split_line[1] + ",");
              } else if (split_line[0].equals("chrY")) {
                String temp =
                    temp_genome_data.get(
                        temp_genome_data.size() - 1); // Store the value already there
                temp_genome_data.remove(temp_genome_data.size() - 1);

                temp = temp + split_line[1];
                temp_genome_data.add(temp);

                end_of_genome = true;
              } else
                temp_genome_data.add(
                    split_line[1] + "," + split_line[1]); // The current line is an autosome
            }
            break;
        }
      }
    } // while ((line = genome_file_reader.readLine()) != null)
    genome_file_reader.close();
    return temp_genome_data;
  } // importGenomeData
Exemplo n.º 8
0
  void run() throws Exception {
    System.setOut(new PrintStream(new FileOutputStream("tmp.out")));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1 << 13);
    int N = Integer.parseInt(br.readLine());
    int[] len =
        new int[] {
          64, 32, 16, 8, 4, 2, 1, 96, 48, 24, 12, 6, 3, 112, 56, 28, 14, 7, 120, 60, 30, 15, 124,
          62, 31, 126, 63, 127
        };
    String[] onpu =
        new String[] {
          "R1",
          "R2",
          "R4",
          "R8",
          "R16",
          "R32",
          "R64",
          "R1.",
          "R2.",
          "R4.",
          "R8.",
          "R16.",
          "R32.",
          "R1..",
          "R2..",
          "R4..",
          "R8..",
          "R16..",
          "R1...",
          "R2...",
          "R4...",
          "R8...",
          "R1....",
          "R2....",
          "R4....",
          "R1.....",
          "R2.....",
          "R1......"
        };
    String[] dp = new String[max];
    dp[0] = "R1.A";
    //        debug(dp[0]);
    for (int i = 1; i < max; i++) {
      String ns = null;
      for (int j = 0; j < onpu.length; j++) {
        int ni = i - len[j];
        if (ni >= 0) {
          String s1 = dp[ni] + onpu[j];
          if (ns == null || isleast(s1, ns)) {
            ns = s1;
          }
        }
      }
      for (int j = 0; j < onpu.length; j++) {
        int ni = i - len[j];
        if (ni >= 0) {
          String s1 = onpu[j] + dp[ni];
          if (isleast(s1, ns)) {
            ns = s1;
          }
        }
      }
      dp[i] = ns;
    }

    //        debug(dp);

    for (int n = 0; n < N; n++) {
      String[] rests = br.readLine().split("R");
      int[] dots = new int[rests.length - 1];
      for (int i = 1; i < rests.length; i++)
        for (int j = rests[i].length() - 1; j >= 0 && rests[i].charAt(j) == '.'; j--) dots[i - 1]++;
      //            debug(rests, dots);
      int[] nums = new int[rests.length - 1];
      for (int i = 1; i < rests.length; i++)
        nums[i - 1] = Integer.parseInt((rests[i].split("\\."))[0]);
      int sum = 0;
      for (int i = 0; i < nums.length; i++) {
        sum += 64 / nums[i];
        sum += (64 / nums[i]) - ((64 / nums[i]) >> dots[i]);
      }
      //            debug(sum);
      int mod = sum;

      StringBuffer f = new StringBuffer("");
      for (; mod >= max; mod -= 192) {
        f.append("R1.R1.");
      }
      //            debug(rests, sum, mod, max);
      String res = dp[mod].replace("R1.A", f.toString());
      System.out.println(res);
    }
  }
Exemplo n.º 9
0
  /**
   * Reads the annotation file. Annotation files are located under the folder annotation of the
   * software directory.
   *
   * @throws IOException
   */
  private void readAnnotationFile(String annotationFileName) throws IOException {

    // Read and process annotation files.
    //
    //	String annotationFileName = "annotation/" + chipType + "_Annotation.csv";
    //

    numAnnotatedProbeSet = 0;

    BufferedReader annotationFile = null;

    try {
      annotationFile = new BufferedReader(new FileReader(annotationFileName));

      String rowAnnotation;

      while ((rowAnnotation = annotationFile.readLine()) != null) {
        numAnnotatedProbeSet++;
      }

    } catch (Exception e) {
      isSuccessfulOpenAnnotationFile = false;
    } finally {
      if (annotationFile != null) {
        annotationFile.close();
      }
    }

    probeSetID = new String[numAnnotatedProbeSet];
    alleleA = new double[numAnnotatedProbeSet];
    alleleB = new double[numAnnotatedProbeSet];

    intensityNormal = new double[numAnnotatedProbeSet];
    intensityTumor = new double[numAnnotatedProbeSet];

    copyNumber = new double[numAnnotatedProbeSet];
    chrID = new String[numAnnotatedProbeSet];
    location = new int[numAnnotatedProbeSet];
    isGenotypeAB = new boolean[numAnnotatedProbeSet];
    probeSetType = new int[numAnnotatedProbeSet];
    isOutlier = new boolean[numAnnotatedProbeSet];

    for (int i = 0; i < isOutlier.length; i++) {
      isOutlier[i] = true;
    }

    annotationFile = null;

    try {
      annotationFile = new BufferedReader(new FileReader(annotationFileName));

      String rowAnnotation;
      int rowNum = 0;

      while ((rowAnnotation = annotationFile.readLine()) != null) {
        String[] rowSplit = null;
        rowSplit = rowAnnotation.split(",");

        probeSetID[rowNum] = rowSplit[0];
        chrID[rowNum] = rowSplit[1];
        location[rowNum] = Integer.parseInt(rowSplit[2]);
        rowNum++;
      }
    } catch (Exception e) {
      isSuccessfulOpenAnnotationFile = false;
    } finally {
      if (annotationFile != null) {
        annotationFile.close();
      }
    }
  }
Exemplo n.º 10
0
 String ns() throws IOException {
   while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());
   return st.nextToken();
 }
Exemplo n.º 11
0
  public void solve() throws Exception {

    String s = br.readLine();
    String[] sp = s.split(" ");
    int n = parseInt(sp[0]);
    int m = parseInt(sp[1]);
    int fl = 0;
    int hf = 0;
    int zr = 0;
    for (int i = 0; i < n; i++) {
      s = br.readLine();
      sp = s.split(" ");
      for (int j = 0; j < sp.length; j++) {
        if (sp[j].equals("11")) {
          fl++;
        } else if (sp[j].equals("00")) {
          zr++;
        } else {
          hf++;
        }
      }
    }
    int[][] ans = new int[n][m];
    int fla = fl % m;
    int row = 0;
    int col = 0;
    if (fl > 0) {
      for (row = 0; row < n; row++) {
        for (col = 0; col < m; col++) {
          ans[row][col] = 1;
          fl--;
          if (fl == 0) {
            break;
          }
        }
        if (fl == 0) {
          break;
        }
      }
      col++;
    }

    if (col == m) {
      row++;
      col = 0;
    }
    if (hf > 0) {
      for (int j = m - 1; j >= col; j--) {
        ans[row][j] = 2;
        hf--;
        if (hf == 0) {
          break;
        }
      }
    }
    boolean flag = true;
    for (int i = n - 1; i >= 0; i--) {
      if (hf == 0) break;
      for (int j = m - 1; j >= 0; j--) {
        if (flag) {
          ans[i][j] = 3;
        } else {
          ans[i][j] = 2;
        }
        hf--;
        if (hf == 0) break;
      }
      flag = !flag;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (j != 0) {
          bw.write(" ");
        }
        if (ans[i][j] == 1) {
          bw.write("11");
        } else if (ans[i][j] == 2) {
          bw.write("01");
        } else if (ans[i][j] == 3) {
          bw.write("10");
        } else {
          bw.write("00");
        }
      }
      bw.write("\n");
    }
  }
Exemplo n.º 12
0
 private long nextLong() throws IOException {
   String s = br.readLine();
   return parseLong(s);
 }
Exemplo n.º 13
0
 private int nextInt() throws IOException {
   String s = br.readLine();
   return parseInt(s);
 }
Exemplo n.º 14
0
 private String nextS() throws IOException {
   String s = br.readLine();
   return s;
 }