fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. const int N = 7;
  6.  
  7. static void Main(string[] args)
  8. {
  9. int n = 0;
  10. int[,] helix = new int[N, N];
  11.  
  12. int x0 = 0;
  13. int xn = N - 1;
  14. int y0 = 0;
  15. int yn = N - 1;
  16.  
  17. while (n < N * N)
  18. {
  19. for (int x = x0; x <= xn; x++)
  20. {
  21. helix[y0, x] = ++n;
  22. }
  23.  
  24. y0++;
  25.  
  26. for (int y = y0; y <= yn; y++)
  27. {
  28. helix[y, xn] = ++n;
  29. }
  30.  
  31. xn--;
  32.  
  33. for (int x = xn; x >= x0; x--)
  34. {
  35. helix[yn, x] = ++n;
  36. }
  37.  
  38. yn--;
  39.  
  40. for (int y = yn; y >= y0; y--)
  41. {
  42. helix[y, x0] = ++n;
  43. }
  44.  
  45. x0++;
  46. }
  47.  
  48. for (int x = 0; x < N; x++)
  49. {
  50. for (int y = 0; y < N; y++)
  51. {
  52. Console.Write("{0}\t", helix[x, y]);
  53. }
  54. Console.WriteLine();
  55. }
  56.  
  57. Console.ReadKey();
  58. }
  59. }
Success #stdin #stdout 0.02s 15812KB
stdin
Standard input is empty
stdout
1	2	3	4	5	6	7	
24	25	26	27	28	29	8	
23	40	41	42	43	30	9	
22	39	48	49	44	31	10	
21	38	47	46	45	32	11	
20	37	36	35	34	33	12	
19	18	17	16	15	14	13