武汉科技大学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: ...
随机推荐
- 解决.VS2012+EF5.0开发的网站在window server2003上无法部署的问题(转载)
转载:http://www.cnblogs.com/eggTwo/p/3653825.html (一)前 言 ...
- 史上最全的css hack
<!DOCTYPE html> <html> <head> <title>Css Hack</title> <style> #t ...
- part3
我就不刁旭概念什么的问题了哈~直接进入工作中所通用的一些有关object的方法和属性 1).for/in 属性的遍历~他遍历的对象没有特定的顺序,而且只能枚举出所有用户自定义的属性,不能枚举出某些预定 ...
- [Python 3.x 官方文档翻译]The Python Tutorial Python教程
Python is an easy to learn, powerful programming language. It has efficient high-level data structur ...
- 父Prefab与子prefab问题
PrefabRevolution 原文:http://framebunker.com/blog/poor-mans-nested-prefabs/ (溜还是老外溜啊) 有些时候需要在Prefab里 ...
- Android 把从网络获取的图片缓存到内存中
1:activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
- ural 1348 Goat in the Garden 2
http://acm.timus.ru/problem.aspx?space=1&num=1348 #include <cstdio> #include <cstring&g ...
- ffdshow 源代码分析1 : 整体结构
ffdshow是一个非常强大的DirectShow解码器,封装了ffmpeg,libmpeg2等解码库.它也提供了丰富的加工处理选项,可以锐化画面,调节画面的亮度等等.不止是视频,FFDShow现在同 ...
- Manor
Description Bob有n个正整数,他将这n个整数根据大小划分成两部分.对于小于等于k的整数放在集合A中,其余的放在集合B中.每次他从集合B中取出一个最大的值,将其变成0放入A集合中.然后将A ...
- HDU_2052——画矩形
Problem Description Give you the width and height of the rectangle,darw it. Input Input contains a ...