13杭电warmup1 1001 Children's Day
来源:互联网 发布:linux 让环境变量生效 编辑:程序博客网 时间:2024/06/01 08:55
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4706
用一个三维数组来存贮要表示的矩阵,先画几个特例找规律,记住这个N是倒的...
代码:
#include<iostream>#include<cstdio>using namespace std;char p[11][11][11];int main(){ for(int i=1;i<11;i++) for(int j=1;j<11;j++) for(int k=1;k<11;k++) p[i][j][k]=' '; int cnt=0; for(int i=3;i<=10;i++) { for(int j=1;j<=3*i-2;j++) { if(j<=i) { p[i][j][1]=char('a'+cnt%26); } else if(j<=2*i-2) { p[i][2*i-j][j-i+1]=char('a'+cnt%26); } else { p[i][j-2*i+2][i]=char('a'+cnt%26); } cnt++; } } for(int i=3;i<=10;i++) { for(int j=1;j<=i;j++) { for(int k=1;k<=i;k++) cout<<p[i][j][k]; cout<<endl; } }}
小白书上有一题蛇形数组输出,顺便写了一下
代码:
#include<iostream>#include<vector>#include<cstring>using namespace std;int a[100][100];bool vis[100][100];void init(){ memset(vis,0,sizeof(vis));}int main(){ int n; while(cin>>n) { init(); int i,j; i=0;j=0; int way=0; int count=0; while(count<n*n) { if(!vis[i][j]&&i<n&&j<n) { a[i][j]=count+1; // cout<<i<<' '<<j<<endl; vis[i][j]=1; count++; } else if(way==0) { if(j+1<n&&!vis[i][j+1]) j++; else way=(way+1)%4; } else if(way==1) { if(i+1<n&&!vis[i+1][j]) i++; else way=(way+1)%4; } else if(way==2) { if(j-1>=0&&!vis[i][j-1]) j--; else way=(way+1)%4;; } else { if(i-1>=0&&!vis[i-1][j]) i--; else way=(way+1)%4; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) cout<<a[i][j]<<' '; cout<<endl; } }}
- 13杭电warmup1 1001 Children's Day
- Children's Day
- Rainy Children's Day
- Children's Day
- HDU4706:Children's Day
- HDU4706-Children's Day
- Children's Day
- HDU4706 Children's Day
- 杭电ACM 1297 Children’s Queue
- 杭电ACM 1297 Children’s Queue
- 杭电1297-Children’s Queue
- 杭电ACM 1297 Children’s Queue
- 杭电 1297 Children’s Queue .
- 杭电1297 Children’s Queue
- 杭电 2100 Children’s Queue
- hdu 4706 Children's Day
- hdu 4706 Children's Day
- hdoj 4706 Children's Day
- Android录音及播放功能实现
- 网易游戏面试题
- VC程序采用动态链接库方式且静态链接MFC方法
- 搜索市场变局:少了云云,剩了搜狗
- Oracle Interval-Partition 解决Range分区大难题
- 13杭电warmup1 1001 Children's Day
- hdu 4747
- how to select a transparent background image in ms paint.
- hanno-----显示递归时间
- 实现sqrt和pow函数
- 判断是否第一次运行APP,以便是否进入APP介绍界面。
- linux如何去获取帮助
- TransactionScope事务
- iOS 单例模式