您的位置:首页 > 其它

华为oj蛇形矩阵

2015-11-20 21:09 183 查看
#include<iostream>
using namespace std;
void GetResult(int Num,char *pResult)
{
int start = 1;
int ystart = 1;
int xstep = 2;
int mstep = 2;
int ystep = 1;
if(Num == 1)
{
cout<<start<<endl;
}
else
{
cout<<start<<" ";
while(ystep != Num)
{
if(xstep !=(Num+1))
{
int t = xstep;
++xstep;
start += t;
if(xstep !=(Num+1))
cout<<start<<" ";
else
cout<<start<<endl;
}
else
{
++mstep;
xstep = mstep;
start = ystart;
start += ystep;
ystart = start;
if(xstep != (Num+1))
cout<<start<<" ";
else
cout<<start<<endl;
++ystep;
}
}

}
}
int main()
{
int n;
char *pResult;
while(cin>>n)
{
GetResult(n,pResult);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: