2014年美团校招笔试题解(更新ING……)

前几天参加了美团的校招笔试, 结果状态不好, 答得跟屎一样, 现在考完了总结一下好了。

5. 旋转二维数组

SouthEast

分析

就是一道找规律的题

代码

#include <iostream>

using namespace std;

#define N 3

class Solution
{
public:
	void print_rotate_matrix(int matrix[N][N], int n)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < i + 1; j++)
				cout << matrix[j][j-i+n-1] << ' ';
			cout << endl;
		}

		for (int i = 0; i < n - 1; i++)
		{
			for (int j = 0; j < n - i - 1; j++)
				cout << matrix[i+j+1][j] << ' ';
			cout << endl;
		}
	}
};

int main()
{
	int matrix[N][N] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

	Solution s;
	s.print_rotate_matrix(matrix, N);

	return 0;
}

参考

http://blog.csdn.net/cow__sky/article/details/39226677

本文章迁移自http://blog.csdn.net/timberwolf_2012/article/details/39399955

/** * RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. * LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/ /* var disqus_config = function () { this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable }; */ (function() { // DON'T EDIT BELOW THIS LINE var d = document, s = d.createElement('script'); s.src = 'https://chenzz.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })();