fork download
  1. import java.util.Collections;
  2. import java.util.Set;
  3. import java.util.Vector;
  4. import java.util.List;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. char[][][] covers = { // book samples in 2D arrays
  11. {{'_','_','_','_','_','_'},
  12. {'|','X','X',' ',' ','|'},
  13. {'|',' ',' ','X',' ','|'},
  14. {'|','U','X',' ',' ','|'},
  15. {'|','U',' ','x','X','|'},
  16. {'-','-','-','-','-','-'}},
  17.  
  18. {{'~','_','_','_','_','_'},
  19. {'|',' ',' ',' ',' ','|'},
  20. {'|',' ',' ',' ',' ','}'},
  21. {'{',' ','H',' ',' ','|'},
  22. {'|',' ',' ',' ',' ','|'},
  23. {'~','-','~','-','-','-'}},
  24.  
  25. {{'_','_','_','_','_','_'},
  26. {'|','p','y','f','g','|'},
  27. {'|','c','r','l','a','|'},
  28. {'|','o','e','u','i','|'},
  29. {'|','d','h','t','n','|'},
  30. {'-','-','-','-','-','-'}},
  31.  
  32. {{'~','~','~','~','~','~'},
  33. {'{',' ',' ',' ',' ','}'},
  34. {'{',' ',' ',' ',' ','}'},
  35. {'{',' ',' ',' ',' ','}'},
  36. {'{',' ',' ',' ',' ','}'},
  37. {'~','~','~','~','~','~'}}
  38. };
  39.  
  40. Main bc = new Main();
  41.  
  42. //Vector<Character>[][] C = (Vector<Character>[][]) new Vector[4][6];
  43. List<Character>[][] C = (List<Character>[][]) new List[4][6];
  44.  
  45. //turn the 2D array of chars into the appropriate type
  46. for (int k = 0; k < 4; k++)
  47. for (int i = 0; i < 6; i++) {
  48. C[k][i] = new Vector<Character>();
  49. for (int j = 0; j < 6; j++)
  50. C[k][i].add(new Character(covers[k][i][j]));
  51. }
  52.  
  53. for (List<Character>[] A : C)
  54. System.out.println(bc.f(A)); // f is d()
  55.  
  56. }
  57.  
  58. int f(List<Character>[]c){int s=0,i=3;for(c[0].addAll(c[5]);i>1;)S(50*--i-5,c[0]);for(c[5].clear();i<5;c[5].addAll(c[i++]))s+=c[i].remove(0)-c[i].remove(4);for(S(32,c[5]);c[5].size()>0;i++)S(c[5].get(0),c[5]);return i-5-c[0].size()+s;}void S(int x,List c){c.removeAll(Collections.singleton((char)x));}
  59.  
  60. }
Success #stdin #stdout 0.08s 33324KB
stdin
Standard input is empty
stdout
3
-4
16
-20