670 - The dog task bad format input

The forum to report every bug you find or tell us what you'd like to find in UVa OJ

Moderator: Board moderators

Post Reply
New poster
Posts: 9
Joined: Fri Dec 29, 2006 3:34 pm

670 - The dog task bad format input

Post by kamiloj » Tue Jul 20, 2010 9:33 pm

the test case have a mistake according the definition.

The first line of each dataset contains two integers N and M, separated by a space ( ). The second line contains N pairs of integers , separated by spaces. The third line contains M pairs of integers , separated by spaces.

so if you try to read with a bufferreader with this definition, you are going to get RTE because the second line does not contain N pairs, but less pairs.

this code only do the read process that not have to be wrong according the definition.

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public Main() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int casos = Integer.parseInt(br.readLine());
		while (casos-- != 0) {
			// read blank line between datasets

			// read n and m
			StringTokenizer st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());

			readPair(n, br.readLine());
			readPair(m, br.readLine());

	// read n pairs of integers
	private void readPair(int n, String line) {
		StringTokenizer st = new StringTokenizer(line);
		for (int i = 0; i < n; i++) {
			Integer.parseInt(st.nextToken());// readX
			Integer.parseInt(st.nextToken());// readY

	public static void main(String[] args) throws IOException {
		new Main();


Post Reply

Return to “Bugs and suggestions”