武汉科技大学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: ...
随机推荐
- AtomicInteger小小的理解
这里仅仅是验证多线程环境下,AtomicInteger的安全性. 通过源码不难发现两点: 1.value属性是volatile修饰 2.使用了unsafe的CAS操作 通过上述两点,实现非阻塞同步(乐 ...
- 1像素HR技巧(兼容各浏览器)
hr{color:#ccc;height:1px;border:0px;border-top:1px solid #ccc;margin:0px;padding:0px;overflow:hidden ...
- Chrome下的语音控制框架MyVoix.js使用篇(四)
在上一篇博文中,我为大家介绍了myvoix.js中的smart learning模块,以及何如使用该功能.(myvoix.js的源码地址会在每一篇文章末尾放出) 文本将拓展 Chrome下的语音控制框 ...
- shell中使用sqlplus及调试相关
五.为了安全要求每次执行shell都手工输入密码$ vi test5.sh #!/bin/bashecho -n "Enter password for u_test:"read ...
- Delphi default属性
Delphi default属性 Delphi控件指定属性的时候可以加上Default关键字,例如property Color default clBtnface.一直以为这个是构造类的时候的默认值, ...
- 【android】adb连接几个常见问题(遇到再新增)
不知道为什么,每次连接手机,都提示 adb server is out of date,偶尔也会提示not found 每次去百度,都好多方法---终于有一种方法非常靠谱,遂,记录之--- 问题一:o ...
- encodeURI和encodeURIComponent的比较
encodeURI和encodeURIComponet函数都是javascript中用来对URI进行编码,将相关参数转换成UTF-8编码格式的数据.URI在进行定位跳转时,参数里面的中文.日文等非AS ...
- 关闭myeclipse中jsp的校验功能
window--->preference--->Myeclipse--->Validation,取消下图红框中的选中状态.
- openwrt network interface(openwrt中的网络接口)
这篇算是对openwrt网络接口的一个翻译吧,源地址:http://wiki.openwrt.org/doc/networking/network.interfaces network的接口类型:物理 ...
- Oracle11g完全卸载步骤
Oracle11g完全卸载步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->Oracle - OraHome ...