public void save() { BufferedWriter sourceFile = null; try { String sourceText = sourceArea.getText(); String cleanText = cleanupSource(sourceText); if (cleanText.length() != sourceText.length()) { sourceArea.setText(cleanText); String message = String.format( "One or more invalid characters at the end of the source file have been removed."); JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE); } sourceFile = new BufferedWriter(new FileWriter(sourcePath, false)); sourceFile.write(cleanText); setSourceChanged(false); setupMenus(); } catch (IOException ex) { ex.printStackTrace(); } finally { if (sourceFile != null) { try { sourceFile.close(); } catch (IOException ignore) { } } } }
void pln(String s) { try { bw.write(s); bw.write(System.lineSeparator()); } catch (Exception ex) { } }
public void saveAs() { Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>(); if (fileExt.equals("m") || fileExt.equals("mac")) { filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)")); filters.add( new RopeFileFilter( new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)")); } else { filters.add( new RopeFileFilter( new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)")); filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)")); } filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)")); RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters); chooser.setDialogTitle("Save Source File"); String fileName = String.format("%s.%s", baseName, fileExt); chooser.setSelectedFile(new File(selectedPath, fileName)); JTextField field = chooser.getTextField(); field.setSelectionStart(0); field.setSelectionEnd(baseName.length()); File file = chooser.save(ROPE.mainFrame); if (file != null) { selectedPath = file.getParent(); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); writer.write(sourceArea.getText()); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (writer != null) { writer.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } }
/** @param args */ public static void main(String[] args) throws Exception { File file = new File("input.txt"); if (file.exists()) { System.setIn(new BufferedInputStream(new FileInputStream("input.txt"))); } out = System.out; bw = new BufferedWriter(new PrintWriter(out)); // sc = new Scanner(System.in); br = new BufferedReader(new InputStreamReader(System.in)); C231 t = new C231(); t.solve(); bw.close(); }
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"); } }
void pl(String s) { try { bw.write(s); } catch (Exception ex) { } }