mihuyo笔试查漏补缺

1.首先是一堆考察基础的不定项选择

2.编程题两道,一道是矩阵的顺时针打印


#include <vector>
#include <iostream>
#include <opencv2/opencv.hpp>   // Include OpenCV API
using namespace cv;
using namespace std;
#include <iostream>
#include <vector>
using namespace std;
char out(vector<vector<char> > &r, char &start, int N, int M, int time)//从字符start开始,只打印N*M的最外面一层
{

	int l = 0, h = 0;
	char s = start;
	int wdown = 0;
	for (l = time; l < M - time; l++)//上
	{
		r[time][l] = s;
		s++;
		if (s > 'Z') s = 'A';
	}
	for (h = time + 1; h < N- time; h++)//右
	{
		r[h][M - time - 1] = s;
		s++;
		if (s > 'Z') s = 'A';
	}
	for (l = M - time - 2; l >= time&&time<N-time-1; l--)//下,需要注意的是当只有一行或一列时会出现重复写的情况
	{
		r[N - time - 1][l] = s;
		s++;
		if (s > 'Z') s = 'A';
	}
	for (h = N - time - 2; h > time&&time<M-time-1; h--)//左
	{
		r[h][time] = s;
		s++;
		if (s > 'Z') s = 'A';
	}
	//for (auto i : r)
	//{
	//	for (auto j : i)
	//		if(j!=' ')cout << j << " ";
	//		else cout << "  ";
	//	cout << endl;
	//}
	return s;
}
int main()
{
	int n =5,m =8;
	
	vector<vector<char> > re(n, vector<char> (m));
	int min = n < m ? n : m;
	char s = 'A';
	for (int time = 0; time <( min+1)/2; time++)
		s = out(re, s, n, m, time);
	for (auto i : re)
	{
		for (auto j : i)
			cout << j << " ";
		cout << endl;
	}
	return 0;
}

逻辑上并不困难,主要是需要注意一些代码上的细节,算是在笔试中考察代码基本功的题目。

第二道编程题是道字符串的正则匹配:

“.”表示任意字符,“+”表示对前一字符的一次或多次使用,“*”表示对前一字符的零次或多次使用

示例:abbc与ab*c,匹配成功   正则匹配在底层代码中的原理是有穷自动机,(利用图的结构去解决)

主要解题思路:一般利用动态规划的思路去做

猜你喜欢

转载自blog.csdn.net/weixin_42067304/article/details/108688404