No older revisions available
No older revisions available
느낀점 ¶
- 역시 끝차 대장이 젤루 쎄다아..;;;ㅁ;;;
- 익숙치 않은 환경탓에 디자인이 좀더 나빠진듯..ㅎㅎㅎ 대충 때웠지만 나름대로 잘 된듯 하다.ㅋ (아닌가?ㅎㅎ)
- 구조체를 썼으면 나아졌을 뻔 했지만.. 요구사항이 늘어났을때 만들었어야 했는데.. vi가 익숙치 않아 많이 수정하는쪽은 되도록 피했다는..ㅋㅋ
- 익숙치 않은 환경탓에 디자인이 좀더 나빠진듯..ㅎㅎㅎ 대충 때웠지만 나름대로 잘 된듯 하다.ㅋ (아닌가?ㅎㅎ)
- 구조체를 썼으면 나아졌을 뻔 했지만.. 요구사항이 늘어났을때 만들었어야 했는데.. vi가 익숙치 않아 많이 수정하는쪽은 되도록 피했다는..ㅋㅋ
1차 버전 ¶
~cpp #include <iostream> #include <string> using namespace std; #define MOVED_POINT 1 bool IsHaveZero(int worldSizeX, int worldSizeY, int** target) { for (register int i = 0; i < worldSizeX; ++i) { for (register int j = 0; j < worldSizeY; ++j) { if (0 == target[i][j]) return true; } } return false; } int main() { int** myWorld; int worldSizeX = 0; int worldSizeY = 0; //// 월드 초기화 //// cout << "input world size \n>>"; cin >> worldSizeX >> worldSizeY; myWorld = new int*[worldSizeX]; for (register int i = 0; i < worldSizeX; ++i) { myWorld[i] = new int[worldSizeY]; for (register int j = 0; j < worldSizeY; ++j) myWorld[i][j] = 0; } //// 시작점 설정 //// int myPointX = 0; int myPointY = 0; cout << "input start point \n>>"; cin >> myPointX >> myPointY; //// 이동경로 입력 //// string moveRotate; cout << "input move rotate\n>>"; cin >> moveRotate; //// 종료 메시지 입력 //// cout << "input End Num 999\n>>"; int endNum; cin >> endNum; //// 이동 처리 //// const int MOVE_TYPE = 8; const int ADD_X[MOVE_TYPE] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ADD_Y[MOVE_TYPE] = {-1, -1, 0, 1, 1, 1, 0, -1}; int moveNum = 0; myWorld[myPointX][myPointY] = MOVED_POINT; for (register int i = 0; i < strlen(moveRotate.c_str()); ++i) { myPointX += ADD_X[moveRotate[i] - '0']; myPointY += ADD_Y[moveRotate[i] - '0']; ++moveNum; myWorld[myPointX][myPointY] = MOVED_POINT; if (false == IsHaveZero(worldSizeX, worldSizeY, myWorld)) break; } cout << moveNum << endl; for (register int i = 0; i < worldSizeY; ++i) { for (register int j = 0; j < worldSizeX; ++j) { cout << myWorld[j][i]; } cout << endl; } return 0; }
2차 버전 ¶
~cpp #include <iostream> #include <string> using namespace std; #define MOVED_POINT 1 #define NUMBER_PLAYER 2 bool IsHaveZero(int worldSizeX, int worldSizeY, int** target) { for (register int i = 0; i < worldSizeX; ++i) { for (register int j = 0; j < worldSizeY; ++j) { if (0 == target[i][j]) return true; } } return false; } int main() { int** myWorld; int worldSizeX = 0; int worldSizeY = 0; //// 월드 초기화 //// cout << "input world size \n>>"; cin >> worldSizeX >> worldSizeY; myWorld = new int*[worldSizeX]; for (register int i = 0; i < worldSizeX; ++i) { myWorld[i] = new int[worldSizeY]; for (register int j = 0; j < worldSizeY; ++j) myWorld[i][j] = 0; } //// 시작점 설정 //// string moveRotate[NUMBER_PLAYER]; int myPointX[NUMBER_PLAYER]; int myPointY[NUMBER_PLAYER]; for (int i = 0; i < NUMBER_PLAYER; ++i) { cout << "input start point \n>>"; cin >> myPointX[i] >> myPointY[i]; //// 이동경로 입력 //// cout << "input move rotate\n>>"; cin >> moveRotate[i]; } //// 종료 메시지 입력 //// cout << "input End Num 999\n>>"; int endNum; cin >> endNum; //// 이동 처리 //// const int MOVE_TYPE = 8; const int ADD_X[MOVE_TYPE] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ADD_Y[MOVE_TYPE] = {-1, -1, 0, 1, 1, 1, 0, -1}; int moveNum[NUMBER_PLAYER] = {0,}; for (register int i = 0; i < NUMBER_PLAYER; ++i) myWorld[myPointX[i]][myPointY[i]] = MOVED_POINT; bool isChanged = true; for (register int i = 0; isChanged; ++i) { isChanged = false; for (register int j = 0; j < NUMBER_PLAYER; ++j) { if (i < strlen(moveRotate[j].c_str())) { isChanged = true; myPointX[j] += ADD_X[moveRotate[j][i] - '0']; myPointY[j] += ADD_Y[moveRotate[j][i] - '0']; ++moveNum[j]; myWorld[myPointX[j]][myPointY[j]] = MOVED_POINT; if (false == IsHaveZero(worldSizeX, worldSizeY, myWorld)) break; } } } for (register int i = 0; i < NUMBER_PLAYER; ++i) cout << moveNum[i] << endl; for (register int i = 0; i < worldSizeY; ++i) { for (register int j = 0; j < worldSizeX; ++j) { cout << myWorld[j][i]; } cout << endl; } return 0; }
3차 버전 ¶
~cpp #include <iostream> #include <string> using namespace std; #define NUMBER_PLAYER 999 #define END_NUMBER 999 bool IsHaveZero(int worldSizeX, int worldSizeY, int** target) { for (register int i = 0; i < worldSizeX; ++i) { for (register int j = 0; j < worldSizeY; ++j) { if (0 == target[i][j]) return true; } } return false; } int main() { int numberPlayer = 0; int** myWorld; int worldSizeX = 0; int worldSizeY = 0; //// 월드 초기화 //// cout << "input world size \n>>"; cin >> worldSizeX >> worldSizeY; myWorld = new int*[worldSizeX]; for (register int i = 0; i < worldSizeX; ++i) { myWorld[i] = new int[worldSizeY]; for (register int j = 0; j < worldSizeY; ++j) myWorld[i][j] = 0; } //// 시작점 설정 //// string moveRotate[NUMBER_PLAYER]; int myPointX[NUMBER_PLAYER]; int myPointY[NUMBER_PLAYER]; for (int i = 0; i < NUMBER_PLAYER; ++i) { cout << "input start point \n>>"; cin >> myPointX[i]; if (END_NUMBER == myPointX[i]) break; cin >> myPointY[i]; ++numberPlayer; //// 이동경로 입력 //// cout << "input move rotate\n>>"; cin >> moveRotate[i]; } //// 이동 처리 //// const int MOVE_TYPE = 8; const int ADD_X[MOVE_TYPE] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ADD_Y[MOVE_TYPE] = {-1, -1, 0, 1, 1, 1, 0, -1}; int moveNum[NUMBER_PLAYER] = {0,}; for (register int i = 0; i < numberPlayer; ++i) ++myWorld[myPointX[i]][myPointY[i]]; bool isChanged = true; for (register int i = 0; isChanged; ++i) { isChanged = false; for (register int j = 0; j < numberPlayer; ++j) { if (i < strlen(moveRotate[j].c_str())) { isChanged = true; myPointX[j] += ADD_X[moveRotate[j][i] - '0']; myPointY[j] += ADD_Y[moveRotate[j][i] - '0']; ++moveNum[j]; ++myWorld[myPointX[j]][myPointY[j]]; if (false == IsHaveZero(worldSizeX, worldSizeY, myWorld)) break; } } } for (register int i = 0; i < numberPlayer; ++i) cout << moveNum[i] << endl; for (register int i = 0; i < worldSizeY; ++i) { for (register int j = 0; j < worldSizeX; ++j) { cout << myWorld[j][i]; } cout << endl; } return 0; }
4차버전 ¶
~cpp #include <iostream> #include <string> using namespace std; #define NUMBER_PLAYER 101 #define END_NUMBER 999 bool IsHaveZero(int worldSizeX, int worldSizeY, int** target) { for (register int i = 0; i < worldSizeX; ++i) { for (register int j = 0; j < worldSizeY; ++j) { if (0 == target[i][j]) return true; } } return false; } int main() { int numberPlayer = 0; int** myWorld; int worldSizeX = 0; int worldSizeY = 0; //// 월드 초기화 //// cout << "input world size \n>>"; cin >> worldSizeX >> worldSizeY; myWorld = new int*[worldSizeX]; for (register int i = 0; i < worldSizeX; ++i) { myWorld[i] = new int[worldSizeY]; for (register int j = 0; j < worldSizeY; ++j) myWorld[i][j] = 0; } //// 시작점 설정 //// string moveRotate[NUMBER_PLAYER]; int myPointX[NUMBER_PLAYER]; int myPointY[NUMBER_PLAYER]; int movePoint[NUMBER_PLAYER]; char selectType; for (int i = 0; i < NUMBER_PLAYER; ++i) { cout << "input start point and Type\n>>"; cin >> myPointX[i]; if (END_NUMBER == myPointX[i]) break; cin >> myPointY[i] >> selectType; ++numberPlayer; //// 이동경로 입력 //// cout << "input move rotate\n>>"; cin >> moveRotate[i]; if ('S' == selectType) movePoint[i] = 2; else movePoint[i] = 1; } //// 이동 처리 //// const int MOVE_TYPE = 8; const int ADD_X[MOVE_TYPE] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ADD_Y[MOVE_TYPE] = {-1, -1, 0, 1, 1, 1, 0, -1}; int moveNum[NUMBER_PLAYER] = {0,}; for (register int i = 0; i < numberPlayer; ++i) ++myWorld[myPointX[i]][myPointY[i]]; bool isChanged = true; for (register int i = 0; isChanged; ++i) { isChanged = false; for (register int j = 0; j < numberPlayer; ++j) { for (register int k = 0; k < movePoint[j]; ++k) { if (i * movePoint[j] + k >= strlen(moveRotate[j].c_str())) break; isChanged = true; myPointX[j] += ADD_X[moveRotate[j][i * movePoint[j] + k] - '0']; myPointY[j] += ADD_Y[moveRotate[j][i * movePoint[j] + k] - '0']; ++moveNum[j]; ++myWorld[myPointX[j]][myPointY[j]]; if (false == IsHaveZero(worldSizeX, worldSizeY, myWorld)) break; } } } for (register int i = 0; i < numberPlayer; ++i) cout << moveNum[i] << endl; for (register int i = 0; i < worldSizeY; ++i) { for (register int j = 0; j < worldSizeX; ++j) { cout << myWorld[j][i]; } cout << endl; } return 0; }
5차 버전 ¶
~cpp #include <iostream> #include <string> #include <map> using namespace std; #define NUMBER_PLAYER 101 #define END_NUMBER 999 #define POWER_DELAY 5 #define SLEEP 8 #define NUMBER_OF_TYPE 3 bool IsHaveZero(int worldSizeX, int worldSizeY, int** target) { for (register int i = 0; i < worldSizeX; ++i) { for (register int j = 0; j < worldSizeY; ++j) { if (0 == target[i][j]) return true; } } return false; } int main() { int numberPlayer = 0; int** myWorld; int worldSizeX = 0; int worldSizeY = 0; map<int, bool> foodDatas; //// 월드 초기화 //// cout << "input world size \n>>"; cin >> worldSizeX >> worldSizeY; myWorld = new int*[worldSizeX]; for (register int i = 0; i < worldSizeX; ++i) { myWorld[i] = new int[worldSizeY]; for (register int j = 0; j < worldSizeY; ++j) myWorld[i][j] = 0; } //// 음식 초기화 //// cout << "input food point (-1 is Exit)\n"; int foodX; int foodY; while(1) { cout << ">>"; cin >> foodX; if (-1 == foodX) break; cin >> foodY; foodDatas[foodX * worldSizeY + foodY] = true; } //// 시작점 설정 //// string moveRotate[NUMBER_PLAYER]; int myPointX[NUMBER_PLAYER]; int myPointY[NUMBER_PLAYER]; int moveType[NUMBER_PLAYER]; char selectType; for (int i = 0; i < NUMBER_PLAYER; ++i) { cout << "input start point and Type\n>>"; cin >> myPointX[i]; if (END_NUMBER == myPointX[i]) break; cin >> myPointY[i] >> selectType; ++numberPlayer; //// 이동경로 입력 //// cout << "input move rotate\n>>"; cin >> moveRotate[i]; if ('S' == selectType) moveType[i] = -1; else moveType[i] = 0; } //// 이동 처리 //// const int MOVE_TYPE = 9; const int ADD_X[MOVE_TYPE] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; const int ADD_Y[MOVE_TYPE] = {-1, -1, 0, 1, 1, 1, 0, -1, 0}; int moveNum[NUMBER_PLAYER] = {0,}; for (register int i = 0; i < numberPlayer; ++i) ++myWorld[myPointX[i]][myPointY[i]]; bool isChanged = true; for (register int i = 0; isChanged; ++i) { isChanged = false; for (register int j = 0; j < numberPlayer; ++j) { int moveDelay = 1; if (0 != moveType[j]) { moveDelay = 2; if (moveType[j] > 0) --moveType[j]; } for (register int k = 0; k < moveDelay; ++k) { if (i * moveDelay + k >= strlen(moveRotate[j].c_str())) break; isChanged = true; int oder = moveRotate[j][i * moveDelay + k] - '0'; myPointX[j] += ADD_X[oder]; myPointY[j] += ADD_Y[oder]; if (SLEEP != oder) { ++moveNum[j]; ++myWorld[myPointX[j]][myPointY[j]]; } if (false == IsHaveZero(worldSizeX, worldSizeY, myWorld)) break; } } for (register int j = 0; ; ++j) { for (register int k = 0; k < numberPlayer; ++k) { if (foodDatas[myPointX[k] * worldSizeY + myPointY[k]] && moveType[k] == j) { foodDatas[myPointX[k] * worldSizeY + myPointY[k]] = false; if (-1 != moveType[k]) moveType[k] = POWER_DELAY; } } if (POWER_DELAY == j) j = -2; else if (-1 == j) break; } } for (register int i = 0; i < numberPlayer; ++i) cout << moveNum[i] << endl; for (register int i = 0; i < worldSizeY; ++i) { for (register int j = 0; j < worldSizeX; ++j) { cout << myWorld[j][i]; } cout << endl; } return 0; }