バイトマジックスティックC++コアコード
20632 ワード
タイトルの簡単な説明:2 D構造体を入力し、クリックする位置を指定し、コードを記述して選択した領域のエッジを返します.それ自体も含まれます.
#include
#include
using namespace std;
enum{LEFT = 1, RIGHT = (1 << 1), TOP = (1 << 2), BOTTOM = (1 << 3), LEFT_TOP = (LEFT|TOP), RIGHT_TOP=(RIGHT|TOP), LEFT_BOTTOM=(LEFT|BOTTOM), RIGHT_BOTTOM=(RIGHT|BOTTOM)};
int DIRECTIONS[8] = {LEFT, RIGHT, TOP, BOTTOM, LEFT_TOP, RIGHT_TOP, LEFT_BOTTOM, RIGHT_BOTTOM};
struct Point{
int X;
int Y;
};
class Cell
{
private:
int row;
int column;
int direction;
bool exists;
public:
Cell(int direction, int row, int column, bool exists):direction(direction), row(row), column(column), exists(exists){};
~Cell(void){};
inline int getRow(){
return row;
}
inline int getColumn(){
return column;
}
inline int getDirection(){
return direction;
}
inline bool isExists(){
return exists;
}
std::vector<Point> getSurroundCell(int maxRow, int maxColumn);
Point point;
};
std::vector<Point> Cell::getSurroundCell(int maxRow, int maxColumn){
std::vector<Point> ret;
int direction = 0;
if(row > 0){ //
direction |= TOP;
}
if(row < maxRow - 1){ //
direction |= BOTTOM;
}
if(column > 0){
direction |= LEFT;
}
if(column < maxColumn - 1){
direction |= RIGHT;
}
int directionCount = sizeof(DIRECTIONS) / sizeof(direction);
for(int i = 0; i < directionCount; i++){
int direct = DIRECTIONS[i];
Cell* cell = nullptr;
if((direction & direct) == direct){
switch (direct)
{
case LEFT:
cell = new Cell(direct, row, column - 1, true);
break;
case RIGHT:
cell = new Cell(direct, row, column + 1, true);
break;
case TOP:
cell = new Cell(direct, row - 1, column, true);
break;
case BOTTOM:
cell = new Cell(direct, row + 1, column, true);
break;
/* case LEFT_TOP:
cell = new Cell(direct, row - 1, column - 1, true);
break;
case LEFT_BOTTOM:
cell = new Cell(direct, row + 1, column - 1, true);
break;
case RIGHT_TOP:
cell = new Cell(direct, row - 1, column + 1, true);
break;
case RIGHT_BOTTOM:
cell = new Cell(direct, row + 1, column + 1, true);
break;*/
default:
cell = new Cell(direct, row, column, true);
break;
}
}
if(cell){
point.X = cell->column; //
point.Y = cell->row; //
ret.push_back(point);
}
}
return ret;
}
int main() {
Cell cell = Cell(0,1,2, false); //
std::vector<Point> res = cell.getSurroundCell(2,3); // 、
for(int i=0;i<res.size();i++){
cout << "(" << res[i].X << "," << res[i].Y << ")" << ",";
}
cout << endl;
return 0;
}