Ejemplo n.º 1
1
  // ---------------------------------------------------------------------------
  private void printDependencies() throws TablesawException {
    m_printedDependencies = new HashSet<String>();

    try {
      PrintWriter pw = new PrintWriter(new FileWriter("dependency.txt"));

      pw.println("Targets marked with a * have already been printed");
      // Create a reduced set of stuff to print
      Set<String> ruleNames = new HashSet<String>();

      for (String name : m_nameRuleMap.keySet()) ruleNames.add(name);

      for (String name : m_nameRuleMap.keySet()) {
        Rule rule = m_nameRuleMap.get(name);
        for (String dep : rule.getDependNames()) ruleNames.remove(dep);

        for (Rule dep : rule.getDependRules()) {
          if (dep.getName() != null) ruleNames.remove(dep.getName());
        }
      }

      for (String name : ruleNames) {
        if (!name.startsWith(NAMED_RULE_PREFIX)) printDependencies(name, pw, 0);
      }

      pw.close();
    } catch (IOException ioe) {
      throw new TablesawException("Cannot write to file dependency.txt", -1);
    }
  }
Ejemplo n.º 2
1
 /**
  * This is for debug only: print out training matrices in a CSV type format so that the matrices
  * can be examined in a spreadsheet program for debugging purposes.
  */
 private void WriteCSVfile(
     List<String> rowNames, List<String> colNames, float[][] buf, String fileName) {
   p("tagList.size()=" + tagList.size());
   try {
     FileWriter fw = new FileWriter(fileName + ".txt");
     PrintWriter bw = new PrintWriter(new BufferedWriter(fw));
     // write the first title row:
     StringBuffer sb = new StringBuffer(500);
     for (int i = 0, size = colNames.size(); i < size; i++) {
       sb.append("," + colNames.get(i));
     }
     bw.println(sb.toString());
     // loop on remaining rows:
     for (int i = 0, size = buf.length; i < size; i++) {
       sb.delete(0, sb.length());
       sb.append(rowNames.get(i));
       for (int j = 0, size2 = buf[i].length; j < size2; j++) {
         sb.append("," + buf[i][j]);
       }
       bw.println(sb.toString());
     }
     bw.close();
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 void run() throws IOException {
   BufferedReader f = new BufferedReader(new FileReader("ttwo.in"));
   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ttwo.out")));
   StringTokenizer st;
   int min = 0;
   for (int i = 0; i < 10; i++) {
     st = new StringTokenizer(f.readLine());
     String s = st.nextToken();
     for (int j = 0; j < 10; j++) {
       if (s.charAt(j) == '*') {
         sq[i][j] = 1;
       } else if (s.charAt(j) == '.') {
         sq[i][j] = 0;
       } else if (s.charAt(j) == 'F') {
         fLoc = 10 * i + j;
         sq[i][j] = 0;
       } else {
         cLoc = 10 * i + j;
         sq[i][j] = 0;
       }
     }
   }
   while (fLoc != cLoc) {
     move();
     min++;
     if (min == 160000) {
       out.println(0);
       out.close();
       System.exit(0);
     }
   }
   out.println(min);
   out.close();
   System.exit(0);
 }
Ejemplo n.º 4
0
  public void exportMainlineDataToText() throws IOException {

    for (int key : detectors.keySet()) {

      Double[] flow =
          MyUtilities.scaleVector(
              detectors.get(key).getFlowDataArray(),
              (double) detectors.get(key).getNumberOfLanes());
      Double[] speed = detectors.get(key).getSpeedDataArray();
      Double[] density =
          MyUtilities.scaleVector(
              detectors.get(key).getDensityDataArray(),
              (double) detectors.get(key).getNumberOfLanes());

      PrintWriter outFlow = new PrintWriter(new FileWriter(key + "_flw.txt"));
      PrintWriter outSpeed = new PrintWriter(new FileWriter(key + "_spd.txt"));
      PrintWriter outDensity = new PrintWriter(new FileWriter(key + "_dty.txt"));

      for (int i = 0; i < flow.length; i++) {

        outFlow.println(flow[i]);
        outSpeed.println(speed[i]);
        outDensity.println(density[i]);
      }

      outFlow.close();
      outSpeed.close();
      outDensity.close();
    }
  }
Ejemplo n.º 5
0
  /** Metodo que escreve os clientes num ficheiro */
  public void escreveLocalidades(String fileLocalidades, String fileLigacoes, int nrlocalidades)
      throws FileNotFoundException, IOException {
    PrintWriter printloc = new PrintWriter(fileLocalidades);
    PrintWriter printlig = new PrintWriter(fileLigacoes);

    Collection<Localidade> coll = this.localidades.values();

    for (Localidade l : coll) {
      printloc.print(l.get_Codigopostal() + "|" + l.get_Nome());

      Map<String, Ligacao> ligacoes = l.get_Ligacoes();
      int nrligacoes = ligacoes.size();

      Collection<Ligacao> colllig = ligacoes.values();

      for (Ligacao lig : colllig) {
        printloc.print("|1");
        printlig.println(
            l.get_Codigopostal()
                + "|"
                + lig.get_Localidaded()
                + "|"
                + lig.get_Distancia()
                + "|"
                + lig.get_Taxas());
      }
      printloc.print("\n");

      nrlocalidades--;
      if (nrlocalidades == 0) break;
    }

    printloc.close();
    printlig.close();
  }
 /**
  * closes all files
  *
  * @author [email protected]
  * @date Thu Dec 1 22:00:05 2011
  */
 void closeFiles() {
   try {
     m_wrMkdirs.close();
     m_wrChmods.close();
   } catch (Exception e) {
     System.err.println("ERROR: failed to close files: " + e.toString());
   }
 }
Ejemplo n.º 7
0
  static void eliminarLugarFicheroLOC(Lugar lugar) {
    String fichero = lugar.getFicheroLOC();

    try {
      FileReader fr = new FileReader(fichero);
      BufferedReader br = new BufferedReader(fr);

      String linea;
      ArrayList lineas = new ArrayList();

      do {
        linea = br.readLine();
        if (linea != null) {
          if (!linea.substring(0, lugar.nombre.length()).equals(lugar.nombre)) lineas.add(linea);
        } else break;
      } while (true);
      br.close();
      fr.close();

      FileOutputStream fos = new FileOutputStream(fichero);
      PrintWriter pw = new PrintWriter(fos);

      for (int i = 0; i < lineas.size(); i++) pw.println((String) lineas.get(i));
      pw.flush();
      pw.close();
      fos.close();

    } catch (FileNotFoundException e) {
      System.err.println("error: eliminando " + e);

    } catch (IOException e) {
      System.err.println("error: eliminando 2 : " + e);
    }
  }
Ejemplo n.º 8
0
 public static void main(String[] args) throws IOException {
   BufferedReader f = new BufferedReader(new FileReader("barn1.in"));
   out = new PrintWriter(new BufferedWriter(new FileWriter("barn1.out")));
   StringTokenizer nstr = new StringTokenizer(f.readLine());
   int m = Integer.parseInt(nstr.nextToken());
   int s = Integer.parseInt(nstr.nextToken());
   occupied = new ArrayList<ArrayList<Integer>>();
   occupied.add(new ArrayList<Integer>());
   for (int i = 0; i < s; i++) {
     try {
       nstr = new StringTokenizer(f.readLine());
       occupied.get(0).add(Integer.parseInt(nstr.nextToken()));
     } catch (NullPointerException e) {
       break;
     }
   }
   Collections.sort(occupied.get(0));
   int bound = m - 1;
   if (occupied.get(0).size() - 1 < bound) {
     bound = occupied.get(0).size() - 1;
   }
   for (int i = 0; i < bound; i++) {
     findMaxCut();
   }
   int total = 0;
   int len = occupied.size();
   for (int i = 0; i < len; i++) {
     ArrayList<Integer> arr = occupied.get(i);
     int len2 = arr.size();
     total += arr.get(len2 - 1) - arr.get(0) + 1;
   }
   out.println(total);
   out.close();
   System.exit(0);
 }
Ejemplo n.º 9
0
  public static void main(String args[]) {

    wmatrix wmatrix = new wmatrix();
    wmatrix.start();
    try {
      PrintWriter profilefout =
          new PrintWriter(
              new BufferedWriter(
                  new FileWriter(
                      "profile_"
                          + Data.kinease
                          + "_"
                          + Data.code
                          + "_"
                          + Data.windows_size
                          + ".csv")));

      profilefout.print("Position=");
      for (int j = 0; j < Data.windows_size; j++) {
        profilefout.print("," + (j - Data.windows_size / 2));
      }
      profilefout.println();

      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < Data.windows_size; j++) {
          profilefout.print("," + wm[i][j]);
        }
        profilefout.println();
      }
      profilefout.close();

    } catch (IOException ex) {

    }
  }
Ejemplo n.º 10
0
 public void cutPlaylist() throws Exception {
   if (logger.isDebugEnabled()) logger.debug("Cut Playlist.");
   String st;
   PrintWriter pw =
       new PrintWriter(new BufferedWriter(new FileWriter(new File(this.NAME + ".dec"))));
   BufferedReader br = new BufferedReader(new FileReader(new File(this.NAME)));
   if ((st = br.readLine()) != null) {
     String st2[];
     st = new File(st).toURL().toString();
     st2 = st.split("/");
     StringBuffer stb = new StringBuffer(st2[st2.length - 1]);
     StringBuffer stb2 = stb.reverse();
     String st3 = new String(stb2);
     int i = 0;
     while (st3.charAt(i) != '.') i++;
     String a = st3.substring(i + 1, st3.length());
     pw.print(new StringBuffer(a).reverse());
   }
   while ((st = br.readLine()) != null) {
     pw.println();
     String st2[];
     st = new File(st).toURL().toString();
     st2 = st.split("/");
     StringBuffer stb = new StringBuffer(st2[st2.length - 1]);
     StringBuffer stb2 = stb.reverse();
     String st3 = new String(stb2);
     int i = 0;
     while (st3.charAt(i) != '.') i++;
     String a = st3.substring(i + 1, st3.length());
     pw.print(new StringBuffer(a).reverse());
   }
   pw.close();
   br.close();
 }
Ejemplo n.º 11
0
 public static void addToPlaylist(File[] filesnames) throws Exception {
   if (logger.isDebugEnabled()) logger.debug("Add to playlist (with parameters - filenames[]).");
   File f = new File(Lecteur.CURRENTPLAYLIST.NAME);
   File Fe =
       new File(
           Lecteur.CURRENTPLAYLIST.NAME.substring(0, Lecteur.CURRENTPLAYLIST.NAME.length() - 19)
               + "wssederdferdtdfdgetrdfdte.pl");
   PrintWriter br = new PrintWriter(new BufferedWriter(new FileWriter(Fe)));
   BufferedReader br1 = new BufferedReader(new FileReader(f));
   String st = null;
   while ((st = br1.readLine()) != null) {
     br.println(st);
   }
   for (int i = 0; i < filesnames.length - 1; i++) {
     br.println(filesnames[i].toString());
   }
   br.print(filesnames[filesnames.length - 1].toString());
   br.close();
   br1.close();
   new File(Lecteur.CURRENTPLAYLIST.NAME).delete();
   (new File(
           Lecteur.CURRENTPLAYLIST.NAME.substring(0, Lecteur.CURRENTPLAYLIST.NAME.length() - 19)
               + "wssederdferdtdfdgetrdfdte.pl"))
       .renameTo(new File(Lecteur.CURRENTPLAYLIST.NAME));
 }
Ejemplo n.º 12
0
  // Saves the user info to a file
  public void saveUserInfo(String path) throws IOException {
    // Declare and initialize file object
    File file = new File(path + "\\Personal.txt");

    // Test if the file exists
    if (file.exists()) {
    } else file.createNewFile();

    // Declare and initialize a writer object
    PrintWriter write = new PrintWriter(new FileWriter(file, false));

    // Write information to file
    write.println(first);
    write.println(last);
    write.println(gender);
    write.println(birthDate);
    write.println(address);
    write.println(phoneNumber);
    write.println(province);
    write.println(city);
    write.println(postal);
    write.println(sin);

    write.close();
  } // End of saveUserInfo method
Ejemplo n.º 13
0
  private static void getTopDocuments(int num, HashMap<String, Float> scoremap, String filename)
      throws FileNotFoundException {
    PrintWriter out = new PrintWriter(filename);
    Iterator<String> itr = scoremap.keySet().iterator();
    ArrayList<String> urls = new ArrayList<String>();
    ArrayList<Float> scores = new ArrayList<Float>();

    while (itr.hasNext()) {
      String key = itr.next();
      if (scores.size() < num) {
        scores.add(scoremap.get(key));
        urls.add(key);
      } else {
        int index = scores.indexOf(Collections.min(scores));
        if (scores.get(index) < scoremap.get(key)) {
          scores.set(index, scoremap.get(key));
          urls.set(index, key);
        }
      }
    }

    while (scores.size() > 0) {
      int index = scores.indexOf(Collections.max(scores));
      out.println(urls.get(index) + "\t" + scores.get(index));
      urls.remove(index);
      scores.remove(index);
    }
    out.close();
  }
Ejemplo n.º 14
0
  // write output, each sentence on a line
  // <word1>/<postag1> <word2>/<postag2> ...
  public void writeData(Map lbInt2Str, String outputFile) {
    if (data == null) {
      return;
    }

    PrintWriter fout = null;

    try {
      fout = new PrintWriter(new FileWriter(outputFile));

      // main loop for writing
      for (int i = 0; i < data.size(); i++) {
        List seq = (List) data.get(i);
        for (int j = 0; j < seq.size(); j++) {
          Observation obsr = (Observation) seq.get(j);
          fout.print(obsr.toString(lbInt2Str) + " ");
        }
        fout.println();
      }

      fout.close();

    } catch (IOException e) {
      System.out.println("Couldn't create file: " + outputFile);
      return;
    }
  }
Ejemplo n.º 15
0
  /**
   * This is for book production only: print out training matrices in a Latex type format so that
   * the matrices can be inserted into my manuscript:
   *
   * <p>\begin{table}[htdp] \caption{Runtimes by Method} \centering
   *
   * <p>\begin{tabular}{|l|l|l|} \hline \textbf{Class.method name}&\textbf{Percent of total
   * runtime}&\textbf{Percent in this method}\\ \hline Chess.main&97.7&0.0\\
   * GameSearch.playGame&96.5&0.0\\
   *
   * <p>Chess.calcPieceMoves&1.7&0.8\\ \hline \end{tabular}
   *
   * <p>\label{tab:runtimes_by_method} \end{table}
   */
  private void WriteLatexFile(
      List<String> rowNames, List<String> colNames, float[][] buf, String fileName) {
    p("tagList.size()=" + tagList.size());
    int SKIP = 6;
    try {
      FileWriter fw = new FileWriter(fileName + ".latex");
      PrintWriter bw = new PrintWriter(new BufferedWriter(fw));
      int size = colNames.size() - SKIP;
      bw.print("\\begin{table*}[htdp]\n\\caption{ADD CAPTION}\\centering\\begin{tabular}{|");
      for (int i = 0; i < size + 1; i++) bw.print("l|");
      bw.println("}\n\\hline");
      bw.print(" &");
      for (int i = 0; i < size; i++) {
        bw.print("\\emph{" + colNames.get(i) + "}");
        if (i < (size - 1)) bw.print("&");
      }
      bw.println("\\\\\n\\hline");

      // bw.printf(format, args)
      // loop on remaining rows:
      for (int i = 0, size3 = buf.length - SKIP; i < size3; i++) {
        bw.print(rowNames.get(i) + "&");
        for (int j = 0, size2 = buf[i].length - SKIP; j < size2; j++) {
          bw.printf("%.2f", buf[i][j]);
          if (j < (size2 - 1)) bw.print("&");
        }
        bw.println("\\\\");
      }
      bw.println("\\hline\n\\end{tabular}\n\\label{tab:CHANGE_THIS_LABEL}\n\\end{table*}");
      bw.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
Ejemplo n.º 16
0
  void run() {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), q = in.nextInt();
    int[] v = new int[n], c = new int[n];
    for (int i = 0; i < n; ++i) v[i] = in.nextInt();
    for (int i = 0; i < n; ++i) c[i] = in.nextInt();

    for (int i = 0; i < q; ++i) {
      int a = in.nextInt(), b = in.nextInt();
      long[] dp = new long[n + 1];
      Node[] heap = new Node[2];
      Arrays.fill(dp, -INF);
      for (int j = 0; j < 2; ++j) heap[j] = new Node(-INF, -1);
      for (int j = 0; j < n; ++j) {
        long val = v[j], maxv = val * b;
        int color = c[j];
        maxv = Math.max(dp[color] + val * a, maxv);
        maxv = Math.max(choose(heap, color) + val * b, maxv);
        dp[color] = Math.max(maxv, dp[color]);
        update(heap, dp[color], color);
      }

      long ret = 0;
      for (int j = 1; j <= n; ++j) ret = Math.max(ret, dp[j]);
      out.println(ret);
    }

    out.close();
  }
Ejemplo n.º 17
0
  public static void main(String[] args) throws IOException {
    input.init(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int depth = input.nextInt();
    int n = (1 << (depth + 1));
    int[] as = new int[n];
    for (int i = 2; i < n; i++) as[i] = input.nextInt();
    int[] paths = new int[n];
    int max = 0;
    ArrayList<Integer>[] under = new ArrayList[n];
    for (int i = 0; i < n; i++) under[i] = new ArrayList<Integer>();
    for (int i = (1 << (depth)); i < n; i++) {
      int cur = i;
      while (cur > 1) {
        under[cur].add(i);
        paths[i] += as[cur];
        cur /= 2;
      }
      max = Math.max(max, paths[i]);
    }
    int res = 0;
    for (int i = 2; i < n; i++) {
      int cm = 0;
      for (int x : under[i]) cm = Math.max(cm, paths[x]);
      int diff = max - cm;
      res += diff;
      for (int x : under[i]) paths[x] += diff;
    }
    out.println(res);
    out.close();
  }
Ejemplo n.º 18
0
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    res.setContentType("text/html");
    try {
      PrintWriter pw = res.getWriter();
      pw.println("<html><head><TITLE>Web-Enabled Automated Manufacturing System</TITLE></head>");
      pw.println(
          "<body><br><br><br><form name=modifyuser method=post action='http://peers:8080/servlet/showUser')");
      v = U.allUsers();
      pw.println("<table align='center' border=0> <tr><td>");
      pw.println(
          "Select User Name To Modify</td><td><SELECT id=select1 name=uid style='HEIGHT: 22px; LEFT: 74px; TOP: 222px; WIDTH: 155px'>");
      pw.println("<OPTION selected value=''></OPTION>");
      for (i = 0; i < v.size(); i++)
        pw.println(
            "<OPTION value="
                + (String) v.elementAt(i)
                + ">"
                + (String) v.elementAt(i)
                + "</OPTION>");
      pw.println(
          "</SELECT></td></tr><tr><td></td><td><input type='submit' name='submit' value='Submit'></td></tr></table></form></body></html>");
      pw.flush();
      pw.close();

    } catch (Exception e) {
    }
  }
Ejemplo n.º 19
0
 public void writeFoundWordsFile() throws IOException {
   PrintWriter pw = new PrintWriter(new FileWriter("src\\LW_5\\output2.txt"));
   for (Map.Entry entry : wordsNumStr.entrySet()) {
     pw.println("Word : " + entry.getKey() + ", String number : " + entry.getValue());
   }
   pw.close();
 }
Ejemplo n.º 20
0
 public void writeFile() throws IOException {
   PrintWriter pw = new PrintWriter(new File("src\\LW_5\\output1.txt"));
   for (String item : tags) {
     pw.println(item);
   }
   pw.close();
 }
Ejemplo n.º 21
0
  public static void main(String args[]) throws Exception {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */

    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    SuperStack stack = new SuperStack();
    PrintWriter out = new PrintWriter(System.out, true);
    for (int i = 0; i < n; i++) {
      String s = in.next();
      if (s.equals("push")) {
        int value = in.nextInt();
        out.println(stack.push(value));
      } else if (s.equals("pop")) {
        int res = stack.pop();
        if (stack.size == 0) {
          out.println("EMPTY");
        } else {
          out.println(res);
        }
      } else if (s.equals("inc")) {
        int x = in.nextInt();
        int d = in.nextInt();
        out.println(stack.inc(x, d));
      }
    }
    out.close();
  }
Ejemplo n.º 22
0
  public static void main(String[] args) throws IOException {
    BufferedReader f = new BufferedReader(new FileReader("beads.in"));
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("beads.out")));
    int n = Integer.parseInt(f.readLine());
    String s = f.readLine();
    int max = Integer.MIN_VALUE;

    for (int i = 0; i < n; i++) {
      String straight = s.substring(i + 1) + s.substring(0, i + 1);
      char[] beads = straight.toCharArray();
      int temp = 0;
      char color = ' ';
      for (int j = 0; j < n; j++) {
        char currColor = beads[j];
        if (color == ' ' && currColor != 'w') color = currColor;
        if (currColor == color || currColor == 'w') temp++;
        else break;
      }

      color = ' ';
      for (int j = n - 1; j > -1; j--) {
        char currColor = beads[j];
        if (color == ' ' && currColor != 'w') color = currColor;
        if (currColor == color || currColor == 'w') temp++;
        else break;
      }
      max = Math.max(temp, max);
    }
    if (max > n) max = n;
    out.println(max);
    out.close();
    System.exit(0);
  }
Ejemplo n.º 23
0
  // Write <Cluster>.ini file
  // Given Hashtable mapping cluster name to Vector of plugin names
  // <Cluster>.ini File format:
  // [ Cluster ]
  // uic = <Agentname>
  // cloned = false
  // [ Plugins ]
  // plugin = <pluginname>
  // ...
  //
  private void dumpClusterInfo(Hashtable all_clusters, String path) throws IOException {
    // Dump hashtable of clusters
    for (Enumeration e = all_clusters.keys(); e.hasMoreElements(); ) {
      String cluster_name = (String) e.nextElement();
      PrintWriter cluster_file;

      try {
        if (path != null) {
          cluster_file = createPrintWriter(path + File.separator + cluster_name + ".ini");
        } else {
          cluster_file = createPrintWriter(cluster_name + ".ini");
        }

        cluster_file.println("[ Cluster ]");
        cluster_file.println("uic = " + cluster_name);
        cluster_file.println("cloned = false\n");
        cluster_file.println("[ Plugins ]");
        Vector plugins = (Vector) (all_clusters.get(cluster_name));
        for (Enumeration p = plugins.elements(); p.hasMoreElements(); ) {
          String plugin = (String) (p.nextElement());
          cluster_file.println("plugin = " + plugin);
        }
        cluster_file.close();
      } catch (IOException exc) {
        System.out.println("IOException:  " + exc);
        System.exit(-1);
      }
    }
  }
Ejemplo n.º 24
0
 public void process() {
   for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) {
     ExtractInterface annot = typeDecl.getAnnotation(ExtractInterface.class);
     if (annot == null) break;
     for (MethodDeclaration m : typeDecl.getMethods())
       if (m.getModifiers().contains(Modifier.PUBLIC)
           && !(m.getModifiers().contains(Modifier.STATIC))) interfaceMethods.add(m);
     if (interfaceMethods.size() > 0) {
       try {
         PrintWriter writer = env.getFiler().createSourceFile(annot.value());
         writer.println("package " + typeDecl.getPackage().getQualifiedName() + ";");
         writer.println("public interface " + annot.value() + " {");
         for (MethodDeclaration m : interfaceMethods) {
           writer.print("  public ");
           writer.print(m.getReturnType() + " ");
           writer.print(m.getSimpleName() + " (");
           int i = 0;
           for (ParameterDeclaration parm : m.getParameters()) {
             writer.print(parm.getType() + " " + parm.getSimpleName());
             if (++i < m.getParameters().size()) writer.print(", ");
           }
           writer.println(");");
         }
         writer.println("}");
         writer.close();
       } catch (IOException ioe) {
         throw new RuntimeException(ioe);
       }
     }
   }
 }
Ejemplo n.º 25
0
 public static void clearPlaylist(Playlist pl) throws Exception {
   String s = pl.NAME;
   // (new File(s)).delete();
   (new File(s + ".dec")).delete();
   PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(s))));
   pw.close();
 }
Ejemplo n.º 26
0
 public void totalExport() {
   File expf = new File("export");
   if (expf.exists()) rmrf(expf);
   expf.mkdirs();
   for (int sto = 0; sto < storeLocs.size(); sto++) {
     try {
       String sl =
           storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-");
       File estore = new File(expf, sl);
       estore.mkdir();
       File log = new File(estore, LIBRARY_NAME);
       PrintWriter pw = new PrintWriter(log);
       for (int i = 0; i < store.getRowCount(); i++)
         if (store.curStore(i) == sto) {
           File enc = store.locate(i);
           File dec = sec.prepareMainFile(enc, estore, false);
           pw.println(dec.getName());
           pw.println(store.getValueAt(i, Storage.COL_DATE));
           pw.println(store.getValueAt(i, Storage.COL_TAGS));
           synchronized (jobs) {
             jobs.addLast(expJob(enc, dec));
           }
         }
       pw.close();
     } catch (IOException exc) {
       exc.printStackTrace();
       JOptionPane.showMessageDialog(frm, "Exporting Failed");
       return;
     }
   }
   JOptionPane.showMessageDialog(frm, "Exporting to:\n   " + expf.getAbsolutePath());
 }
Ejemplo n.º 27
0
  public static void main(String args[]) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("important.in"));
    PrintWriter out = new PrintWriter("important.out");

    int n = rInt(in.readLine(), 1, MaxN);

    boolean[] t = new boolean[26];

    for (int i = 0; i < n; i++) {
      String s = in.readLine();
      if (s.length() > MaxL) throw new Exception("String is too long");
      char f = checkFormula(s.trim());
      t[f - 'A'] = true;
    }
    ;

    out.println("Yes");

    boolean flag = false;
    for (int i = 0; i < 26; i++)
      if (t[i]) {
        if (flag) out.print(" | ");
        String let = "" + (char) (i + 'A');
        out.print(let + " | ~" + let);
        flag = true;
      }
    ;

    out.close();
  };
  public void run() {
    try {
      File f2 = new File(MATCH_LOG_FILE);
      if (f2.exists() && !f2.isDirectory()) {
        matchReader = new BufferedReader(new FileReader(MATCH_LOG_FILE));
        String sCurrentLine;

        for (int i = 0; i < logCount; i++) {
          matchReader.readLine();
        }

        while ((sCurrentLine = matchReader.readLine()) != null) {
          if (sendToBackOffice(sCurrentLine)) {
            System.out.println("Updating log count");
            logWriter = new PrintWriter(new FileWriter("c:\\temp\\countBackOffice.log"));
            logWriter.print(++logCount);
            logWriter.close();
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (matchReader != null) matchReader.close();
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }
Ejemplo n.º 29
0
  public void run() {
    System.out.println("New Communication Thread Started");

    try {
      PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
      BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

      String inputLine;
      String[] inputTemp = new String[3];

      while ((inputLine = in.readLine()) != null) {
        System.out.println("Server: " + inputLine);

        out.println(inputLine);

        if (inputLine.equals("Bye.")) break;
      }

      out.close();
      in.close();
      clientSocket.close();
    } catch (IOException e) {
      System.err.println("Problem with Communication Server");
      System.exit(1);
    }
  }
Ejemplo n.º 30
0
  public static void main(String[] args) throws IOException {
    input.init(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = input.nextInt(), k = input.nextInt();
    int[] data = new int[n];
    for (int i = 0; i < n; i++) data[i] = input.nextInt();
    int res = 0;
    for (int i = 0; i < k; i++) {
      HashSet<Integer> set = new HashSet<Integer>();
      for (int j = i; j < n; j += k) set.add(data[j]);
      int max = 1;
      for (int x : set) {
        int count = 0;
        for (int j = i; j < n; j += k) {
          if (data[j] == x) count++;
        }
        max = Math.max(max, count);
      }
      res += (n / k) - max;
    }
    out.println(res);

    out.close();
  }