package com.menzus.gcj._2012.qualification.c;

import com.menzus.gcj.common.InputBlockParser;
import com.menzus.gcj.common.OutputProducer;
import com.menzus.gcj.common.impl.AbstractProcessorFactory;

public class CProcessorFactory extends AbstractProcessorFactory<CInput, COutputEntry> {
    public CProcessorFactory(String inputFileName) {
	super(inputFileName);
    }

    @Override
    protected InputBlockParser<CInput> createInputBlockParser() {
	return new CInputBlockParser();
    }

    @Override
    protected OutputProducer<CInput, COutputEntry> createOutputProducer() {
	return new COutputProducer();
    }
}

package recyclednumbers.recycler;

public class Recycler {

    public int countPairs(int startValue, int endValue) {

        int count = 0;

        for (int i = startValue; i < endValue; i++) {
            for (int j = i + 1; j <= endValue; j++) {
                if (isRecycledPair(i, j)) {
                    count++;
                }
            }
        }

        return count;

    }

    public boolean isRecycledPair(int original, int target) {

        String originalString = original + "";

        for (int i = originalString.length() - 1; i > 0; i--) {
            String testString = originalString.substring(i) + originalString.substring(0, i);

            if (Integer.parseInt(testString) == target) {
                return true;
            }

        }

        return false;

    }
}
