相机的cced传感与cced hr有什么区别
发布网友
发布时间:2022-04-22 13:35
我来回答
共1个回答
热心网友
时间:2023-08-25 04:19
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Solution {public:
char* flag;
bool hasPath(char* matrix, int rows, int cols, char* str)
{
flag = str;
if (matrix == NULL || str == NULL) return false;
char* current = matrix;
char* tempStr= matrix;
bool result = false;
while (tempStr <matrix +rows*cols)
{
/* cout << "*current:" << *current << " ";
cout << "*str:" << *str << endl;*/
if (*tempStr == *str)
{
visisted.clear();//要忘清楚visisted(问题1)
setVisisted(rows, cols);
char* current = tempStr;
cout << "*current:" << *current << " ";
cout << "*str:" << *str << endl;
result = getPath(matrix,rows,cols, str, current);
cout << endl << endl;;
}
if (result == true) break;
++tempStr;
}
return result;
}
bool getPath(char* matrix, int rows, int cols, char* str, char* current)
{
if (*str == '\0')return true;//注意:句放同位置结论同能放面位置(问题3)
if (current matrix || current >= matrix + rows*cols) return false;
if(visisted[current - matrix]==true)return false;
// visisted[current - matrix] = true;//该数符合要求才设置true!!!!!!!!!!!!!!设置处错误(问题2)
//if (*str == '\0')return true;//注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cout << "*str:" << *str << " ";
cout << "*current:" << *current << endl;
cout << "str标:" << str - flag<<" " ;
cout << "current标:" << current - matrix << endl;
if (*str != *current) return false;
//if (*str == *current)//两者相等
visisted[current - matrix] = true;//该数符合要求才设置true!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return getPath(matrix, rows, cols, str + 1, current - 1) ||
getPath(matrix, rows, cols, str + 1, current + 1) ||
getPath(matrix, rows, cols, str + 1, current - cols) ||
getPath(matrix, rows, cols, str + 1, current + cols);
}
vector visisted;//访问标志数组已经访问则设置true访问
void setVisisted(int rows,int cols)
{
int i = 0;
while (i<rows*cols)
{
visisted.push_back(false);
++i;
}
}
};int main(){
Solution so;
//cout << 1 / 10 << endl;
//char* matrix = "abcesfcsadee";
//char* matrix = "ABCEHJIGSFCSLOPQADEEMNOEADIDEJFMVCEIFGGS";
//char* str = "SLHECCEIDEJFGGFIE";
char* matrix = "AAAAAAAAAAAA";
char* str = "AAAAAAAAAAAA";
char* str1 = "bcced";
char* str2 = "abcb";
char* str3 = "abc";
int rows = 3;
int cols = 4;
//cout<<"bcced匹配结:"<<so.hasPath(matrix, rows, cols, str1)<<endl;
//cout << "abcb匹配结:" << so.hasPath(matrix, rows, cols, str2) << endl;
//cout << "abc匹配结:" << so.hasPath(matrix, rows, cols, str3) << endl;
cout << "SLHECCEIDEJFGGFIE匹配结:" << so.hasPath(matrix, 3, 4, str) << endl;
return 0;
}