武汉科技大学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: ...
随机推荐
- part3
我就不刁旭概念什么的问题了哈~直接进入工作中所通用的一些有关object的方法和属性 1).for/in 属性的遍历~他遍历的对象没有特定的顺序,而且只能枚举出所有用户自定义的属性,不能枚举出某些预定 ...
- 找不到请求的 .Net Framework Data Provider。可能没有安装。
解决方法: 安装Microsoft SQL Server Compact 4.0. 安装Microsoft SQL Server Compact 4.0之后,程序运行正常. 问题的原因就是程序连接.s ...
- iOS——文件操作NSFileManager (创建、删除,复制,粘贴)
iOS——文件操作NSFileManager (创建.删除,复制,粘贴) iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视 ...
- uva 10026 Shoemaker's Problem
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- Ruby on Rails Tutorial读书笔记-1
只是怕忘了命令,全部撸一次,记个大概.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 安装Ruby之前,先要安装RVM: curl -L https://get.rvm.io | bas ...
- qt-solutions提供了8个开源项目
其实这是官方提供的源代码,至于为什么会另建项目,而没有整合到QT项目里去,我猜可能有2个原因: 1. 这几个项目本身不完善,并且也不是QT项目的核心,因此没有必要花精力去完善 2. 一定程度上可以维护 ...
- VC++中调用cmd的集中方式
1. system方法: 原型: int __cdecl system(const char *); 例如: system("ipconfig"); 2. WinExec方法: 相 ...
- javascript 误用this指针 的情况
理解了this指针后,我们再来看看一些很容易误用this指针的情况. 示例1——内联式绑定Dom元素的事件处理函数 <script type="text/javascript" ...
- BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 48 Solved: 41[S ...
- C++ Primer笔记(一):字符串、向量和数组
3.1 命名空间 using namespace::name; using namespace::std using std::cin -- 头文件不应该包含using 3.2 类型string ge ...