I need to read from standard input. I am not familiar with BufferedReader and so far have only used Scanner. The scanner (or probably something inside my code) continues to give me TLE. Now the problem is that the BufferedReader seems to skip some lines, and I keep getting a NumberFormatException.
Here is my code:
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(reader.readLine()); for(int i = 0; i < cases && cases <= 10; i++) { int numLines = Integer.parseInt(reader.readLine()); String[] lines = new String[numLines + 1]; HashSet<String> pat = new HashSet<String>(); for(int j = 0; j < numLines && j <= 10; j++) { String l = reader.readLine(); String patternStr = "\\W+"; String replaceStr = ""; Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(l.toString()); String m = matcher.replaceAll(replaceStr); lines[j] = m; getPatterns(m, pat); System.out.println(m); }
The error occurs after the second entry. Please, help.
source share