面试1

1. 请你简要说明C++和C的区别。

  https://blog.csdn.net/bitboss/article/details/62884694

2. 请谈一谈,系统如何提高并发性?

  https://blog.csdn.net/gupao123456/article/details/86594406

3. 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一      个格子。如果一条路径经过了矩阵中的某一个格子,则之后不能再次进入这个格子。 例如 a b c e s f c s a d e e 这样的3 X 4 矩阵中包含一条字符串"bcced"的路径,但是矩阵中不包       含"abcb"路径,因为字符串的第一个字符b占据了矩阵中的第一行第二个格子之后,路径不能再次进入该格子。

  

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <limits.h>

using namespace std;

bool findPath(char arr[][100], int row, int col, int x, int y, char* str, int index, bool judge[][100])
{
    if (index >= strlen(str))
    {
        return true;
    }
    if(!(x < row && y < col))
    {
        return false;
    }
    if (arr[x][y] == str[index] && judge[x][y] == false)
    {
        judge[x][y] = true;
        if (findPath(arr, row, col, x+1, y, str, index+1, judge) ||
            findPath(arr, row, col, x, y+1, str, index+1, judge) ||
            findPath(arr, row, col, x-1, y, str, index+1, judge) ||
            findPath(arr, row, col, x, y-1, str, index+1, judge)
            )
            {
                return true;
            }
            else
            {
                return false;
            }
    }
    else
    {
        judge[x][y] = false;
        return false;
    }

}

bool HashPath(char arr[][100], int row, int col, char* str, bool judge[][100])
{
    if (str == NULL || strlen(str) == 0)
    {
        return true;
    }
    bool b = false;
    for (int i = 0; i < row; ++i)
    {
        for (int j = 0; j < col; ++j)
        {
            b = findPath(arr, row, col, i, j, str, 0, judge);
            if (b)
            {
                return true;
            }
        }
    }
    return b;
}

int main(int argc, char** argv)
{
    int row, col;
    cin >> row >> col;
    char arr[100][100];
    bool judge[100][100];

    for (int i = 0; i < 100; ++i)
    {
        for (int j = 0; j < 100; ++j)
        {
            judge[i][j] = false;
        }
    }

    for (int i = 0; i < row; ++i)
    {
        for (int j = 0; j < col; ++j)
        {
            cin >> arr[i][j];
        }
    }

    char str[100];
    cin >> str;

    bool result = HashPath(arr, row, col, str, judge);
    if (result)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

 

posted on 2019-01-24 12:46  NEU-2015  阅读(237)  评论(0编辑  收藏  举报

导航