import java.util.List; import java.util.ArrayList; import java.util.Iterator; public class Main { number372(); } public static void number372(){ IFilter<Integer> mod3_is_0 = new IFilter<Integer>(){ }; IFilter<Integer> mod7_is_2 = new IFilter<Integer>(){ }; IListFilter<Integer> flt = new SimpleListFilter<Integer>( new ChainFilter<Integer>( mod3_is_0, mod7_is_2 ) ); IFormatter<List<Integer>> fmt = new ListFormatter<Integer>( ":", ",", 10 ); List<Integer> ls = new SequenceIntegerListGenerator( 1, 1, 1000 ).generate(); List<Integer> modLs = flt.filter(ls); fmt.format(modLs.subList(0,90)) ); } public static interface IFilter<Type> { boolean pass(Type n); } public static interface IListFilter<Type> { List<Type> filter(List<Type> ls); } public static interface IFormatter<Type> { } public static interface IListGenerator<Type> { List<Type> generate(); } public static class ChainFilter<Type> implements IFilter<Type> { IFilter[] m_filters; public ChainFilter(IFilter<Type> ... filters ){ m_filters = filters; } public boolean pass(Type n){ for( int i = 0; i < m_filters.length; i++ ){ if( !m_filters[i].pass(n) ){ return false; } } return true; } } public static class SimpleListFilter<Type> implements IListFilter<Type> { IFilter<Type> m_filter; SimpleListFilter(IFilter<Type> filter){ m_filter = filter; } public List<Type> filter(List<Type> ls){ List<Type> res = new ArrayList<Type>(); Iterator<Type> it = ls.iterator(); while(it.hasNext()){ Type n = it.next(); if( this.m_filter.pass(n) ){ res.add(n); } } return res; } } public static class ListUtil<Type> { Iterator<Type> it = ls.iterator(); it.next().toString(): ""; while( it.hasNext() ){ s += delim + it.next(); } return s; } } public static class ListFormatter<Type> implements IFormatter<List<Type>> { int m_nElemsPerLine; String m_delimLineNum; String m_delimElem; ListUtil<Type> m_lutil; ListFormatter( String delimLineNum, String delimElem, int nElemsPerLine ){ m_delimLineNum = delimLineNum; m_delimElem = delimElem; m_nElemsPerLine = nElemsPerLine; m_lutil = new ListUtil<Type>(); } private static int min( int x, int y ){ return x < y ? x : y; } List<Type> subL; for( int i = 0; (i*m_nElemsPerLine) < ls.size(); i ++ ){ subL = ls.subList( (i*m_nElemsPerLine), min( ( (i+1) *m_nElemsPerLine), ls.size() ) ); res += (i+1) + m_delimLineNum; res += m_lutil.join(subL,m_delimElem); } return res; } } public static class SequenceIntegerListGenerator implements IListGenerator <Integer> { ArrayList<Integer> m_list; SequenceIntegerListGenerator( int first, int diff, int length ){ m_list = new ArrayList<Integer>(); for( int i = 0; i < length; i++ ){ m_list.add( first + (i*diff) ); } } public List<Integer> generate(){ } } }
Standard input is empty
1:3,6,12,15,18,21,24,27,33,36 2:39,42,45,48,54,57,60,63,66,69 3:75,78,81,84,87,90,96,99,102,105 4:108,111,117,120,123,126,129,132,138,141 5:144,147,150,153,159,162,165,168,171,174 6:180,183,186,189,192,195,201,204,207,210 7:213,216,222,225,228,231,234,237,243,246 8:249,252,255,258,264,267,270,273,276,279 9:285,288,291,294,297,300,306,309,312,315