加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Ural319(输出格式)

发布时间:2020-12-13 20:15:25 所属栏目:PHP教程 来源:网络整理
导读:题目链接:点击打开链接 解题思路: 分别从右上角和左下角斟酌,和姐姐跟我说的上1题差不多????? 完全代码: #include algorithm#include iostream#include cstring#include climits#include cstdio#include string#include cmath#include map#include queue

题目链接:点击打开链接


解题思路:

分别从右上角和左下角斟酌,和姐姐跟我说的上1题差不多?????


完全代码:

#include <algorithm> #include <iostream> #include <cstring> #include <climits> #include <cstdio> #include <string> #include <cmath> #include <map> #include <queue> using namespace std; typedef long long LL; const int MOD = int(1e9)+7; const int INF = 0x3f3f3f3f; const double EPS = 1e⑼; const double PI = acos(⑴.0); //M_PI; const int maxn = 101; int g[maxn][maxn]; int main() { #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int n; while(cin >> n) { int key = 1; for(int k = n ; k >= 1 ; k --) { int i = 1; int j = k; g[i][j] = key; key ++; while(i + 1 <= n && j + 1 <= n) { j ++; i ++; g[i][j] = key; key ++; } } key = n * n; for(int k = 1 ; k <= n - 1 ; k ++) { int i = n; int j = k; g[i][j] = key; key --; while(i - 1 >= 1 && j - 1 >= 1) { i --; j --; g[i][j] = key; key --; } } for(int i = 1 ;i <= n ; i ++) { for(int j = 1; j <= n ; j ++) { cout << g[i][j] << " "; } cout << endl; } } }

更多精彩请访问:点击打开链接

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读