信仰2016

导航

 

从左上角起按照蛇形排列0...100

#include<iostream>
using namespace std;
int main()
{
	int i, j, a[100][100], k, m;
	int n = 1, p = 2;
	k = 0;
	int num = 0;
	for (k = 0; k < 10; k++)
	{
		m = k % 2;
		if (m == 0)
		{
			for (i = 0; i < k + 1; i++)
			{
				a[i][k - i] = num;
				num++;
			}
		}
		else
		{
			for (i = k; i >= 0; i--)
			{
				a[i][k - i] = num;
				num++;
			}
		}
	}
	for (k = 10; k <= 18; k++)
	{
		m = k % 2;
		if (m == 0)
		{
			for (i = n; i < 10; i++)
			{
				a[i][k - i] = num;
				num++;
			}
			n = n + 2;
		}
		else
		{
			for (i = 9; i >= p; i--)
			{
				a[i][k - i] = num;
				num++;
			}
			p = p + 2;
		}
	}
	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 10; j++)
		{
			if (a[i][j] < 10)
			{
				cout << "0" << a[i][j] << " ";
			}
			else
			{
				cout << a[i][j] << " ";
			}
		}
		cout << endl;
	}
}

  

posted on 2016-05-09 22:35  信仰2016  阅读(585)  评论(0编辑  收藏  举报