fork download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Player
  6. {
  7. public static void main(String args[])
  8. {
  9. Scanner in = new Scanner(System.in);
  10. PrintWriter out = new PrintWriter(System.out);
  11.  
  12. short width = in.nextShort(); // the number of cells on the X axis
  13. short height = in.nextShort(); // the number of cells on the Y axis
  14.  
  15. if (in.hasNextLine()) {
  16. in.nextLine();
  17. }
  18.  
  19. String node[] = new String[height];
  20.  
  21. for(short y = 0; y < height; ++y)
  22. {
  23. node[y] = in.nextLine();
  24. }
  25.  
  26. for(short y = 0; y < height; ++y)
  27. {
  28. for(short x = 0; x < width; ++x)
  29. {
  30. if (node[y].charAt(x) == '0')
  31. {
  32. out.printf(String.valueOf(x)+" "+String.valueOf(y)+" ");
  33. short x2, y2, ansX = -1, ansY = -1;
  34. for (x2 = (short)(x+1); x2 < width; ++x2)
  35. {
  36. if (node[y].charAt(x2) == '0')
  37. {
  38. ansX = x2;
  39. ansY = y;
  40. break;
  41. }
  42. }
  43. out.printf(String.valueOf(ansX)+" "+String.valueOf(ansY)+" ");
  44. ansX = -1;
  45. ansY = -1;
  46.  
  47. for(y2 = (short)(y+1); y2 < height; ++y2)
  48. {
  49. if (node[y2].charAt(x) == '0')
  50. {
  51. ansX = x;
  52. ansY = y2;
  53. break;
  54. }
  55. }
  56. out.printf(String.valueOf(ansX)+" "+String.valueOf(ansY)+"\n");
  57. x = (short)(x2-1);
  58. }
  59. }
  60. }
  61. out.flush();
  62. }
  63. }
Success #stdin #stdout 0.13s 29280KB
stdin
2 2
00
0.
stdout
0 0 1 0 0 1
1 0 -1 -1 -1 -1
0 1 -1 -1 -1 -1