博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
直角三角形填数
阅读量:4625 次
发布时间:2019-06-09

本文共 742 字,大约阅读时间需要 2 分钟。

#include 
#include
int map[100][100];int main(){ memset(map, 0, sizeof(map)); int n, i, j,count; int x = 1, y = 0; int tot = 1; scanf("%d", &n); count = (1 + n) * n / 2; //printf("%d\n\n",count); while(tot != count+1) { while(y < n && !map[x][y+1])//横行 { map[x][++y] = tot++; } if(tot == count+1) break; while(x < n && !map[x+1][y-1])//斜行 { map[++x][--y] = tot++; } if(tot == count+1) break; while(y > 0 && !map[x-1][y])//竖行 { map[--x][y] = tot++; } if(tot == count+1) break; } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { if(map[i][j] != 0) { printf("%-4d",map[i][j]); } } printf("\n"); } return 0;}

转载于:https://www.cnblogs.com/lgh1992314/archive/2013/03/19/5835162.html

你可能感兴趣的文章
Socket & TCP &HTTP
查看>>
osip及eXosip的编译方法
查看>>
Hibernate composite key
查看>>
[CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
查看>>
keepalived+nginx安装配置
查看>>
vue+element-ui实现表格checkbox单选
查看>>
autofac
查看>>
MacOS 系统终端上传文件到 linux 服务器
查看>>
Excel导出POI
查看>>
兼容性
查看>>
自动执行sftp命令的脚本
查看>>
转 Merkle Tree(默克尔树)算法解析
查看>>
网络编程基础之socket编程
查看>>
各种浏览器的user-agent和
查看>>
Restful levels
查看>>
Phonegap移动开发:布局总结(一) 全局
查看>>
Java 变参函数的实现
查看>>
nrf51 SDK自带例程的解读
查看>>
SESSION技术
查看>>
数据结构(五)之直接插入排序
查看>>