武汉科技大学ACM :1009: 零起点学算法63——弓型矩阵
Problem Description
输出n*m的弓型矩阵
Input
每组输入2个整数 n和m(不大于20)
Output
输出n*m的弓型矩阵,要求左上角元素是1,(每个元素占2个位置,靠右)
Sample Input
4 3
Sample Output
1 2 3
6 5 4
7 8 9
12 11 10 我的代码:
#include<iostream>
#include <iomanip>
using namespace std; int main()
{
int m,n,i,p;
while(cin>>m>>n)
{
for(i=;i<=m;i++)
{
if(i%==)
{
for(p=;p<=n;p++)
if(p!=n)
cout<<setw()<<p+n*(i-)<<" ";
else
cout<<setw()<<p+n*(i-);
cout<<endl;
}
else
{
for(p=;p<=n;p++)
if(p!=n)
cout<<setw()<<(((i-)*n)+(n+-p))<<" ";
else
cout<<setw()<<(((i-)*n)+(n+-p));
cout<<endl;
}
}
}
return ;
}
其他代码:
#include<stdio.h>
int main(){
int m,n;
while(scanf("%d%d",&n,&m)!=EOF)
{
int dir=;
int count=;
for(int i=;i<n;i++){
if(dir){
for(int j=;j<m;j++){ if(j==m-)
{
printf("%2d",++count);
}
else
{
printf("%2d ",++count);
}
} }else{
count=count+m;
for(int j=;j<m;j++){ if(j==m-)
{
printf("%2d",count--);
}
else
{
printf("%2d ",count--);
}
}
count=count+m;
}
dir=!dir;
printf("\n");
} }
}
#include <iostream>
#include<iomanip>
using namespace std; int main()
{
int row,col;
int k=-;
int *a=NULL;
int i,j;
while(cin>>row>>col)
{
k=-;
if(row> || col>)
{
return ;
} a=new int[row*col]; for(i=;i<row;++i)
{
if(i%==)
{
for(j=;j<col;++j)
{
a[i*col+j]=++k;
} }
else
{
for(j=col-;j>=;--j)
{
a[i*col+j]=++k;
}
} }
for(i=;i<row;++i)
{
for(j=;j<col-;++j)
{
cout<<setw()<<a[i*col+j]<<" ";
}
cout<<setw()<<a[i*col+j]<<endl;
} }
return ;
}
武汉科技大学ACM :1009: 零起点学算法63——弓型矩阵的更多相关文章
- Problem D: 零起点学算法95——弓型矩阵
#include<stdio.h> #include<string.h> int main() { ][]; while(scanf("%d%d",& ...
- Problem D: 零起点学算法94——输出矩阵
#include<stdio.h> int main() { ][]; while(scanf("%d %d",&n,&m)!=EOF) { ; ;i& ...
- WUOJ-ACM :1003: 零起点学算法78——牛牛
武汉科技大学ACM :1003: 零起点学算法78--牛牛Problem Description牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中 ...
- 1163: 零起点学算法70——Yes,I can!
1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1164: 零起点学算法71——C语言合法标识符(存在问题)
1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 10 ...
- 1147: 零起点学算法54——Fibonacc
1147: 零起点学算法54--Fibonacc Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 20 ...
- 1145: 零起点学算法52——数组中删数II
1145: 零起点学算法52--数组中删数II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 293 ...
- 1137: 零起点学算法44——多组测试数据输出II
1137: 零起点学算法44--多组测试数据输出II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1136: 零起点学算法43——多组测试数据输出I
1136: 零起点学算法43--多组测试数据输出I Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: ...
随机推荐
- 6 个轻量级并且灵活的 PHP CMS 系统
Anchor CMS Just like its introduction says, Anchor has a very simple UI. The installation takes lite ...
- await使用中的阻塞和并发
本文讨论,通过将Lambda还原成最普通的代码段,来解释上篇提出的疑问.并更正上篇中一些不太正确的写法.最后会给出无需等待Async方法返回值时,对Async方法使用await的建议,供大家参考.第一 ...
- jdbc接口api
java.sql.* 和 javax.sql.* |- Driver接口: 表示java驱动程序接口.所有的具体的数据库厂商要来实现此接口. |- connect(url, properties): ...
- [翻译]只为图片使用IMG标签(Use IMG tags only for Images)
原文地址:Use IMG tags only for Images 首先,补充一些背景知识. web开发人员经常通过在主页预加载(预缓存)将来的页面所用到的一些资源的方式来优化网站的性能.常用的手段是 ...
- 将Altium中的原理图与PCB导出为PDF的步骤与方法
1.通过File-Smart PDF(文件-智能PDF),快捷键F-M打开. 2.选择打印的范围:Current Project还是Current Document,还有生成的PDF的存放位置. 3. ...
- PullToRefreshListView组件的OnItemClickListener中的position下标问题
/** * Pass-through method for {[url=home.php?mod=space&uid=91636]@link[/url] PullToRefreshBase#g ...
- Linux标准输入、输出和错误和文件重定向(转) --- good
标准输入.输出和错误 当我们在shell中执行命令的时候,每个进程都和三个打开的文件相联系,并使用文件描述符来引用这些文件.由于文件描述符不容易记忆,shell同时也给出了相应的文件名.下面就是这些文 ...
- 8.2.1.13 Multi-Range Read Optimization 多个range 读优化
8.2.1.13 Multi-Range Read Optimization 多个range 读优化 读记录使用一个range scan 在一个secondary index 可以导致很多的随机磁盘访 ...
- rsyslog 一重启就会开始同步之前所有通配的日志文件
<pre name="code" class="html">[root@dr-mysql01 zjzc_log]# grep '24/Sep/201 ...
- 【HDOJ】3518 Boring Counting
后缀数组2倍增可解. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 10 ...