Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #define LEFT_WALL (1 << 0) //1
- #define BOTTOM_WALL (1 << 1) //2
- #define RIGHT_WALL (1 << 2) //4
- #define TOP_WALL (1 << 3) //8
- #define TOP_LEFT_CORNER (TOP_WALL | LEFT_WALL)
- #define TOP_RIGHT_CORNER (TOP_WALL | RIGHT_WALL)
- #define BOTTOM_LEFT_CORNER (BOTTOM_WALL | LEFT_WALL)
- #define BOTTOM_RIGHT_CORNER (BOTTOM_WALL | RIGHT_WALL)
- #define Nmax 100
- int H[100][100];
- struct vec2{short x, y;};
- struct Room
- {
- vec2 topLeft;
- vec2 bottomleft;
- vec2 topRight;
- vec2 bottomRight;
- };
- using namespace std;
- std::vector<Room> rooms;
- inline void CreateRoom(int x, int y)
- {
- Room room;
- room.topLeft.x = x;
- room.topLeft.y = y;
- std::cout << "Creating room at " << x<< " " << y << std::endl;
- //top right
- int x_ = x;
- while(H[x_][y] != TOP_RIGHT_CORNER)
- {
- x_++;
- //cout << "topright" << std::endl;
- }
- room.topRight.x = x_;
- room.topRight.y = y;
- //bottom left
- int y_ = y;
- while(H[x][y_] != BOTTOM_LEFT_CORNER){
- y_++;
- cout << "bottomleft" << std::endl;
- }
- room.bottomleft.x = x;
- room.bottomleft.y = y_;
- //bottom right
- x_ = x;
- while(H[x_][y_] != BOTTOM_RIGHT_CORNER){
- x_++;
- cout << "bottomright" << std::endl;
- }
- room.bottomRight.x = x_;
- room.bottomRight.y = y_;
- rooms.push_back(room);
- }
- int main()
- {
- int c; //mode
- int n; //size
- std::ifstream input("test");
- std::ofstream output("testoutput");
- input >> c;
- input >> n;
- cout << "TOP_RIGHT = " << TOP_LEFT_CORNER <<endl;
- if(n > 100)
- {
- std::cout << "halo nem szabad";
- return 0;
- }
- for(int i =0 ; i < n ;i++)
- {
- for(int j =0 ; j < n ;j++)
- {
- input >> H[j][i];
- }
- }
- for(int i =0 ; i < n ;i++)
- {
- for(int j =0 ; j < n ;j++)
- {
- if(H[i][j] & TOP_LEFT_CORNER)
- {
- CreateRoom(i,j);
- }
- }
- }
- if(c == 1)
- output << rooms.size();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement