/* * Author: ry * Created Time: 2017/9/4 21:32:52 * File Name: 1.cpp */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <time.h> using namespace std; const int mm = 1e6+5; #define Max(a,b) a>b?a:b #define Min(a,b) a>b?b:a #define ll long long ll t_cnt; void t_st(){t_cnt=clock();} void t_ot(){printf("you spent : %lldms\n", clock()-t_cnt);} //开始t_st(); //结束t_ot(); int main() { int n ; while ( ~scanf("%d", &n)){ int k = n; int f = 0; for (int i = 1 ; i <= n ; i++){ for (int j = 1; j <= f; j++){ printf ("%d ", j); } for (int j = 1; j <= (2*n-1-2*f); j++){ printf ("%d ", f+1); } for (int j = f; j >= 1; j--){ printf ("%d ", j); } f++; printf ("\n"); } f = n-1; for (int i = n-1; i >= 1; i--){ for (int j = 1; j <= f; j++){ printf ("%d ", j); } for (int j = 1; j <= (2*n-1-2*f); j++){ printf ("%d ", f); } for (int j = f; j >= 1; j--){ printf ("%d ", j); } f--; printf ("\n"); } } return 0; }
原文:http://www.cnblogs.com/ccut-ry/p/7476216.html