fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main()
  5. {
  6. int n;
  7.  
  8. std::cin >> n;
  9.  
  10. std::vector<std::vector<int>> matritsa(n, std::vector<int>(n));
  11.  
  12. int i = 1;
  13.  
  14. for(int d = 0; d < n; d++) {
  15. for(int y = 0; y <= d; y++) {
  16. matritsa[y][d] = i++;
  17. }
  18.  
  19. for(int x = d - 1; x >= 0; x--) {
  20. matritsa[d][x] = i++;
  21. }
  22. }
  23.  
  24. for(std::vector<int>& row : matritsa) {
  25. for(int x : row) {
  26. std::cout << x << '\t';
  27. }
  28.  
  29. std::cout << std::endl;
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 16064KB
stdin
10
stdout
1	2	5	10	17	26	37	50	65	82	
4	3	6	11	18	27	38	51	66	83	
9	8	7	12	19	28	39	52	67	84	
16	15	14	13	20	29	40	53	68	85	
25	24	23	22	21	30	41	54	69	86	
36	35	34	33	32	31	42	55	70	87	
49	48	47	46	45	44	43	56	71	88	
64	63	62	61	60	59	58	57	72	89	
81	80	79	78	77	76	75	74	73	90	
100	99	98	97	96	95	94	93	92	91