public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); StringBuilder b = new StringBuilder(); try (BufferedWriter writer = new BufferedWriter(new FileWriter("out.txt"))) { String line = scanner.nextLine(); boolean skip = false; while(!line.equals(";")) { for(int i = 0;i < line.length();i++) { char c = line.charAt(i); if(c == '<') skip = true; if(!skip) b.append(c); if(c == '>') skip = false; } b.append("\n"); line=scanner.nextLine(); } writer.write(b.toString()); System.out.println("Successfully output to out.txt"); } catch (IOException e) { e.printStackTrace(); } scanner.close(); } }
如果使用python,那么就需要在文件中添加以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
with open("out.txt", "w") as writer: b = "" line = input() skip = False while line != ";": for c in line: if c == '<': skip = True if not skip: b += c if c == '>': skip = False b += "\n" line = input() writer.write(b)