武汉科技大学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: ...
随机推荐
- Sencha Architect 激活方法
Sencha Architect 2是ExtJS和Sencha Touch的官方可视化IDE工具.最新版本是2.2,说是破解,其实是修改License来实现无限试用而已. 1.先下载安装官方软件,大 ...
- 操作css样式
<script type="text/javascript"> //产生一个四位的验证码. function createCode(){ var datas = ['A ...
- css中响应式布局中样式的代码书写方法
代码示例:@media only screen and (min-width: 320px){ html { font-size: 8px !important; } .mulu-zi{ positi ...
- Ubuntu 下对ADT 添加别名(alias)
1:~$ vim .bashrc 2:在打开的.bashrc文件中加入: alias adt='./adt-bundle-linux-x86-20130729/eclipse/eclipse' 3:保 ...
- java构造方法的不同
分为有参数和无参数,还有THIS的使用方法,可用于传递给类,也可用于调用其它构造方法. public class Book { private String name; public Book(){ ...
- BZOJ3564 信号增幅仪
http://www.lydsy.com/JudgeOnline/problem.php?id=3564 思路:先旋转坐标系,再缩进x坐标,把椭圆变成圆,然后做最小圆覆盖. 还有,为什么用srand( ...
- C#控制生成图片的大小
private void button1_Click(object sender, EventArgs e) { using (Bitmap bitmap = new Bitmap("d:\ ...
- [LeetCode 110] - 平衡二叉树 (Balanced Binary Tree)
问题 给出一棵二叉树,判断它是否在高度上是平衡的. 对于本问题,高度上平衡的二叉树定义为:每个节点的两棵子树的深度差永远不大于1的一棵二叉树. 初始思路 根据定义,思路应该比较直接:递归计算每个节点左 ...
- Local System/Network Service/Local Service
// The name of the account under which the service should run// 1 NT AUTHORITY\\SYSTEM 2 NT AUTHORIT ...
- oschina大数据开源软件
Hadoop 图形化用户界面 Hue 大数据可视化工具 Nanocubes 企业大数据平台 RedHadoop 大数据查询引擎 PrestoDB Hadoop集群监控工具 HTools 安全大数据分析 ...