USACO Bronze-Censoring Bug

Hi USACO Forum,
Whenever I submit my code for the problem Bronze 2015 Problem Censoring the grader tells me the following:

Incorrect answer on sample input case – details below
Your output file censor.out:

The correct answer:

Your program wrote this on standard output:

I was wondering as to why I am getting these errors and what I could do to prevent these in the future.

My code is below

import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
			Kattio io = new Kattio("censor");
			String S =;
			String censor =;
			boolean containscensor = S.contains(censor);
			while (S.contains(censor)) {
				S = S.replace(censor, "");

class Kattio extends PrintWriter {
	private BufferedReader r;
	private StringTokenizer st;

	// standard input
	public Kattio() {
		this(, System.out);

	public Kattio(InputStream i, OutputStream o) {
		r = new BufferedReader(new InputStreamReader(i));

	// USACO-style file input
	public Kattio(String problemName) throws IOException {
		super(problemName + ".out");
		r = new BufferedReader(new FileReader(problemName + ".in"));

	// returns null if no more input
	public String next() {
		try {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(r.readLine());
			return st.nextToken();
		} catch (Exception e) {
		return null;

	public int nextInt() {
		return Integer.parseInt(next());

	public double nextDouble() {
		return Double.parseDouble(next());

	public long nextLong() {
		return Long.parseLong(next());


Do you have spaces at the end of your output?

No I don’t believe there are any

What error did you get? Can you attach a screenshot?