文本统计分析
标题:文本统计分析 | 时间限制:1秒 | 内存限制:32768K | 语言限制:不限
有一个文件, 包含以一定规则写作的文本, 请统计文件中包含的文本数量
import java.util.Scanner; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int ans = 0; Queue<Character> cuntQ = new LinkedList<>(); while (sc.hasNext()) { String currentString = sc.nextLine(); char[] chars = currentString.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] == ';') { if (!cuntQ.isEmpty() && cuntQ.peek() == '\\') { } else if (!cuntQ.isEmpty()){ ans ++; while (!cuntQ.isEmpty()) { cuntQ.poll(); } } } else if (chars[i] != ' ') { if (i != 0 && chars[i] == '-' && chars[i-1] == '-' && chars[i+1] != '\'' && chars[i+1] != '"' ) { cuntQ.poll(); break; } cuntQ.offer(chars[i]); } } } if (!cuntQ.isEmpty()) { ans++; } System.out.println(ans); } }