fork(1) download
  1. class StackingBlocks{
  2. public static void main(String[] args){
  3. System.out.println("1 =>");
  4. s(1);
  5. System.out.println("2 =>");
  6. s(2);
  7. System.out.println("3 =>");
  8. s(3);
  9. System.out.println("5 =>");
  10. s(5);
  11. }
  12. static void s(int q){int i,j,x,z;char b;for(i=0;i<q*q+1;i++){z=0;x=0;for(j=0;j<(q*(q+1))/2+1;j++){b=' ';if(x==z){int y=x+1;if((q*q+1-i<=x*x+1&&(q*q+1-i)%(x==0?1:x)==(x==1?0:1))||(y<=q&&q*q+1-i<=y*y+1&&(q*q+1-i)%(y==0?1:y)==(y==1?0:1)))b='+';else if(q*q+1-i<=x*x+1||y<=q&&q*q+1-i<=y*y+1)b='|';x++;z=1;}else{if(q*q+1-i<=x*x+1&&(q*q+1-i)%(x==0?1:x)==(x==1?0:1))b='-';z++;}System.out.print(b);}System.out.println();}}
  13. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
1 =>
++
++
2 =>
 +-+
 | |
 +-+
++ |
++-+
3 =>
   +--+
   |  |
   |  |
   +--+
   |  |
 +-+  |
 | +--+
 +-+  |
++ |  |
++-+--+
5 =>
          +----+
          |    |
          |    |
          |    |
          |    |
          +----+
          |    |
          |    |
          |    |
      +---+    |
      |   +----+
      |   |    |
      |   |    |
      +---+    |
      |   |    |
      |   +----+
   +--+   |    |
   |  +---+    |
   |  |   |    |
   +--+   |    |
   |  |   +----+
 +-+  +---+    |
 | +--+   |    |
 +-+  |   |    |
++ |  |   |    |
++-+--+---+----+