반응형
작년에 멋도 모르고 열심히 짰던 소스입니다 ㅋㅋ
덕분에 이 프로그램을 짠 시점으로부터 저의 실력이 확 늘었던거 같아요
필요한 함수 찾아보고~ 어떻게 작동하는지 알아보고 하는등
제가 과제로 이 프로그램을 짰던 만큼 소스 공유는 조심스럽네요(후배들이 내 소스를 보러올수도있잖아!)
소스가 약 2천줄 정도되는데 이걸 다 쳐보라고 하는건 무리겠죠?ㅎㅎ;; 맨마지막에 소스 올려놓겠습니다
그대로 복사해서 제출하지마시고 어떤아이디어가 사용되고 짜여졌는지 참고만 해주시면 좋겠습니다 ㅎㅎ 좀조잡하지만
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | #include <conio.h>//_kbhit(),_getch() 를쓰기위한 헤더 #include <Windows.h> #include <iostream> #include <stdlib.h>//랜덤쓰기위해서 #include <time.h>//랜덤바꾸기위해서 using namespace std; #include "floor.h" #include "passengers.h" #include "elevators.h" int rest(Passengers &v1, Elevators &v2); void Elevator_GUI(Passengers &v1, Elevators &v2, Floor &v3); void normal_elevator(); void normal_elevator_plus(); void normal_elevator_plus_plus(); void even_odd_elevator(); void up_down_elevator(); int main() { srand((int)time(NULL));//시드값 바꿔주기 int a; while (1) { cout << "\n\t엘리베이터 종합 프로그래밍\n\n" << endl; cout << "1.normal_elevator(평범한 엘리베이터)" << endl; cout << "2.normal_elevator+(첫번째 엘리베이터 우선권)" << endl; cout << "3.normal_elevator++(B2~6F,7F~15F 스위치만 받는 엘리베이터1,2)" << endl; cout << "4.even_odd_elevator(짝수층,홀수층만 내리고타는 엘리베이터)" << endl; cout << "5.up_down_elevator(B2~15왔다갔다 단순한 엘리베이터)" << endl; cout << "6.exit" << endl; cout << "\n번호를 입력해주세요>> " << endl; cin >> a; system("cls"); if (a > 6 || a < 1) cout << "해당 번호는 없습니다 다시 입력해주세요" << endl; if (a == 6) break; switch (a) { case 1: normal_elevator(); break; case 2: normal_elevator_plus(); break; case 3: normal_elevator_plus_plus(); break; case 4: even_odd_elevator(); break; case 5: up_down_elevator(); break; } } return 0; } int rest(Passengers &v1, Elevators &v2) { int rest = 0; for (int i = 0; i <= v1.get_person(); i++) { if (v1.get_act(i) == 1 || v1.get_act(i) == 2) rest++; } rest = rest + v2.get_people1() + v2.get_people2(); return rest; } void Elevator_GUI(Passengers &v1, Elevators &v2, Floor &v3) { for (int i = 16; i >= 2; i--) { cout << "| " << i - 1; if (i - 1 < 10) cout << " "; cout << "F "; if (v2.get_present1() == i) { cout << "■ " << v2.get_present1() - 1; if (v2.get_present1() - 1 < 10) cout << " "; cout << " ■"; } else cout << " "; if (v2.get_present2() == i) { cout << " ■ "; cout << v2.get_present2() - 1; if (v2.get_present2() - 1 < 10) cout << " "; cout << " ■"; } else cout << " "; if (i == 8) cout << "\t(a) 멈춤 (b) 추가승객 (c)생성지목적지설정하는승객생성" << endl; else cout << endl; // cout << "| [" << v3.pget_up(i); if (v3.pget_up(i) < 10) cout << " "; cout << "]▲ "; if (v2.get_present1() == i) { if (v2.get_door1() == 1) cout << " "; else cout << "■"; cout << "[" << v2.get_people1(); if (v2.get_people1() < 10) cout << " "; cout << "]■ "; } else cout << " "; if (v2.get_present2() == i) { if (v2.get_door2() == 1) cout << " "; else cout << "■"; cout << "[" << v2.get_people2(); if (v2.get_people2() < 10) cout << " "; cout << "]■";//엘리베이터 둘째줄 } else cout << " "; if (i == 10) { cout << "\t\t엘리베이터1 목적지: "; if (v2.get_destination1() > 1) cout << v2.get_destination1() - 1 << "F"; else cout << "B" << 2 - v2.get_destination1(); } if (i == 8) cout << "\t(d)승객 생성된 시간 (e)종료"; if (i == 12) cout << "\t\t생성된사람수: " << v1.get_person() << endl; else cout << endl; // cout << "| [" << v3.pget_down(i); if (v3.pget_down(i) < 10) cout << " "; cout << "]▼ "; if (v2.get_present1() == i) cout << "■■■■"; else cout << " "; if (v2.get_present2() == i) cout << " ■■■■";//엘리베이터 셋째줄 else cout << " "; if (i == 10) { cout << "\t\t엘리베이터2 목적지: "; if (v2.get_destination2() > 1) cout << v2.get_destination2() - 1 << "F"; else cout << "B" << 2 - v2.get_destination2(); } if (i == 12) cout << "\t\t남은사람수: " << rest(v1, v2) << endl; else cout << endl; } //////지하 for (int i = 1; i >= 0; i--) { cout << "| B" << 2 - i; if (2 - i < 10) cout << " "; cout << " "; if (v2.get_present1() == i) { cout << "■ B" << 2 - v2.get_present1(); if (2 - v2.get_present1() < 10) cout << " "; cout << "■"; } else cout << " "; if (v2.get_present2() == i) { cout << " ■ B"; cout << 2 - v2.get_present2(); if (2 - v2.get_present2() < 10) cout << " "; cout << "■" << endl; } else cout << " " << endl; // cout << "| [" << v3.pget_up(i); if (v3.pget_up(i) < 10) cout << " "; cout << "]▲ "; if (v2.get_present1() == i) { if (v2.get_door1() == 1) cout << " "; else cout << "■"; cout << "[" << v2.get_people1(); if (v2.get_people1() < 10) cout << " "; cout << "]■ "; } else cout << " "; if (v2.get_present2() == i) { if (v2.get_door2() == 1) cout << " "; else cout << "■"; cout << "[" << v2.get_people2(); if (v2.get_people2() < 10) cout << " "; cout << "]■" << endl;//엘리베이터 둘째줄 } else cout << " " << endl; // cout << "| [" << v3.pget_down(i); if (v3.pget_down(i) < 10) cout << " "; cout << "]▼ "; if (v2.get_present1() == i) cout << "■■■■"; else cout << " "; if (v2.get_present2() == i) cout << " ■■■■" << endl;//엘리베이터 셋째줄 else cout << " " << endl; } } void normal_elevator_plus() { Elevators e; Passengers p; Floor f; int a = 1; Elevator_GUI(p, e, f); Sleep(4000); while (a) { system("cls"); try { if (p.get_person() >= 999) throw p.get_person(); //// p.Produce_passenger(f); e.go_target_np(p); e.go_create_np(f); e.Elevator_state(); e.take_in_out(p, f); e.Elevator_move_take_in_out(p, f); Elevator_GUI(p, e, f); Sleep(5000); p.time_flow(); e.set_door1(); e.set_door2(); } catch (int e) { cout << "경고!더 실행시킬시 승객생성 1000명이상입니다" << endl; cout << "현재 생성된 승객수: " << e << endl; cout << "승객정보를 저장할수 있는공간이 더이상없습니다 프로그램을 종료합니다" << endl; break; } //// if (_kbhit())//키보드 눌렀니 체크 1반환 { switch (_getch())//키보드로 입력받은것 문자임! { case 'a': cout << "재개 아무키나 눌러주세요" << endl; system("pause"); break; case 'b': int x; cout << "추가할 승객수 입력" << endl; cin >> x; for (int i = 0; i < x; i++) p.Produce_passenger(f); break; case 'c': p.produce_choose(f); break; case 'd': system("cls"); p.sleep_time(); system("pause"); break; case 'e': cout << "종료합니다!" << endl; a = 0; } } } } void normal_elevator() { Elevators e; Passengers p; Floor f; int a = 1; Elevator_GUI(p, e, f); Sleep(4000); while (a) { system("cls"); try { if (p.get_person() >= 999) throw p.get_person(); //// p.Produce_passenger(f); e.go_target_n(p); e.go_create_n(f); e.Elevator_state(); e.take_in_out(p, f); e.Elevator_move_take_in_out(p, f); Elevator_GUI(p, e, f); Sleep(5000); p.time_flow(); e.set_door1(); e.set_door2(); } catch (int e) { cout << "경고!더 실행시킬시 승객생성 1000명이상입니다" << endl; cout << "현재 생성된 승객수: " << e << endl; cout << "승객정보를 저장할수 있는공간이 더이상없습니다 프로그램을 종료합니다" << endl; break; } //// if (_kbhit())//키보드 눌렀니 체크 1반환 { switch (_getch())//키보드로 입력받은것 문자임! { case 'a': cout << "재개 아무키나 눌러주세요" << endl; system("pause"); break; case 'b': int x; cout << "추가할 승객수 입력" << endl; cin >> x; for (int i = 0; i < x; i++) p.Produce_passenger(f); break; case 'c': p.produce_choose(f); break; case 'd': system("cls"); p.sleep_time(); system("pause"); break; case 'e': cout << "종료합니다!" << endl; a = 0; } } } } void normal_elevator_plus_plus() { Elevators e; Passengers p; Floor f; int a = 1; Elevator_GUI(p, e, f); Sleep(4000); while (a) { system("cls"); //// p.Produce_passenger(f); e.go_target_npp(p); e.go_create_npp(f); e.Elevator_state(); e.take_in_out(p, f); e.Elevator_move_take_in_out(p, f); Elevator_GUI(p, e, f); Sleep(5000); p.time_flow(); e.set_door1(); e.set_door2(); //// if (_kbhit())//키보드 눌렀니 체크 1반환 { switch (_getch())//키보드로 입력받은것 문자임! { case 'a': cout << "재개 아무키나 눌러주세요" << endl; system("pause"); break; case 'b': int x; cout << "추가할 승객수 입력" << endl; cin >> x; for (int i = 0; i < x; i++) p.Produce_passenger(f); break; case 'c': p.produce_choose(f); break; case 'd': system("cls"); p.sleep_time(); system("pause"); break; case 'e': cout << "종료합니다!!" << endl; a = 0; } } } } void even_odd_elevator() { Elevators e(0, 0, 1, 1); Passengers p; Floor f; int a = 1; Elevator_GUI(p, e, f); Sleep(4000); while (a) { system("cls"); try { if (p.get_person() >= 999) throw p.get_person(); //// p.Produce_passenger_oe(f); e.go_create_oe(f); e.Elevator_state(); e.take_in_out_oe(p, f); e.Elevator_move_take_in_out(p, f); Elevator_GUI(p, e, f); Sleep(5000); p.time_flow(); e.set_door1(); e.set_door2(); } catch (int e) { cout << "경고!더 실행시킬시 승객생성 1000명이상입니다" << endl; cout << "현재 생성된 승객수: " << e << endl; cout << "승객정보를 저장할수 있는공간이 더이상없습니다 프로그램을 종료합니다" << endl; break; } //// if (_kbhit())//키보드 눌렀니 체크 1반환 { switch (_getch())//키보드로 입력받은것 문자임! { case 'a': cout << "재개 아무키나 눌러주세요" << endl; system("pause"); break; case 'b': int x; cout << "추가할 승객수 입력" << endl; cin >> x; for (int i = 0; i < x; i++) p.Produce_passenger(f); break; case 'c': p.produce_choose_oe(f); break; case 'd': system("cls"); p.sleep_time(); system("pause"); break; case 'e': cout << "종료합니다!" << endl; a = 0; } } } } void up_down_elevator() { Elevators e; Passengers p; Floor f; int a = 1; Elevator_GUI(p, e, f); Sleep(4000); while (a) { system("cls"); try { if (p.get_person() >= 999) throw p.get_person(); //// p.Produce_passenger(f); e.go_go(); e.Elevator_state(); e.take_in_out(p, f); e.Elevator_move_take_in_out(p, f); Elevator_GUI(p, e, f); Sleep(5000); p.time_flow(); e.set_door1(); e.set_door2(); } catch (int e) { cout << "경고!더 실행시킬시 승객생성 1000명이상입니다" << endl; cout << "현재 생성된 승객수: " << e << endl; cout << "승객정보를 저장할수 있는공간이 더이상없습니다 프로그램을 종료합니다" << endl; break; } //// if (_kbhit())//키보드 눌렀니 체크 1반환 { switch (_getch())//키보드로 입력받은것 문자임! { case 'a': cout << "재개 아무키나 눌러주세요" << endl; system("pause"); break; case 'b': int x; cout << "추가할 승객수 입력" << endl; cin >> x; for (int i = 0; i < x; i++) p.Produce_passenger(f); break; case 'c': p.produce_choose(f); break; case 'd': system("cls"); p.sleep_time(); system("pause"); break; case 'e': cout << "종료합니다!" << endl; a = 0; } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | #pragma once class Passengers { private: int create[1000];//생성층 int target[1000];//목적층 int act[1000];//0.소멸시&목적달성시 1.올라갈건지 2.내려갈건지(스위치라 생각해도댐) int take[1000];//엘베 타고있음 안타고있음(1/0) int time[1000];//생성되있던 시간 int person;//지금까지 생성된 사람수 public: Passengers()//승객들 초기상태 설정 { for (int i = 0; i < 1000; i++) { create[i] = 0; target[i] = 0; act[i] = 0; take[i] = 0; time[i] = 0; } person = 0; } ~Passengers() { }; int get_create(int a)//create 값 반환 { return create[a]; } int get_target(int a)//target 값 반환 { return target[a]; } int get_act(int a)//act 값 반환 { return act[a]; } int get_take(int a) { return take[a]; } int get_person()//지금까지 생성된 승객수 반환 { return person; } void take_up(int a) { take[a] = 1; } void take_down(int a) { take[a] = 0; } void set_act(int a) { act[a] = 0; } void Produce_passenger(Floor &v1); void time_flow(); void produce_choose(Floor &v1); void sleep_time(); void Produce_passenger_oe(Floor &v1); void produce_choose_oe(Floor &v1); }; void Passengers::Produce_passenger(Floor &v1)//승객만듬&private값설정 { ++person; create[person] = rand() % 17; //0~16뽑기 target[person] = rand() % 17; while (1) { if (create[person] == target[person]) target[person] = rand() % 17; else break; } if (create[person] < target[person])//행동정해줌 { act[person] = 1;//!!이때 person값과 create값을 floor에서 저장해주면? v1.plus_pget_up(create[person]); v1.plus_tget_up(target[person]); } else if (create[person]>target[person]) { act[person] = 2; v1.plus_pget_down(create[person]); v1.plus_tget_down(target[person]); } } void Passengers::time_flow() { for (int i = 0; i < person + 1; i++) time[i] += 5; } void Passengers::produce_choose(Floor &v1) { ++person; int a, b; while (1) { cout << "추가할 승객의 생성지,목적지를 입력해주세요" << endl; cin >> a >> b; if (a == b) cout << "같은수를 입력하셨습니다 다시입력해주세요" << endl; else break; } create[person] = a; target[person] = b; if (create[person] < target[person])//행동정해줌 { act[person] = 1;//!!이때 person값과 create값을 floor에서 저장해주면? v1.plus_pget_up(create[person]); v1.plus_tget_up(target[person]); } else if (create[person]>target[person]) { act[person] = 2; v1.plus_pget_down(create[person]); v1.plus_tget_down(target[person]); } } void Passengers::sleep_time() { for (int i = 1; i < person + 1; i++) { if (act[i] == 0 && take[i] == 0) ; else { cout << i << "번 사람은 생성된지 " << time[i] << "초 만큼 되었습니다" << endl; } } } void Passengers::Produce_passenger_oe(Floor &v1)//승객만듬&private값설정 { ++person; int x = rand() % 2; if (rand() % 2 == 0)//짝수 { create[person] = (rand() % 9) * 2; target[person] = (rand() % 9) * 2; while (1) { if (create[person] == target[person]) target[person] = (rand() % 9) * 2; else break; } } else//홀수 { create[person] = (rand() % 8 + 1) * 2 - 1; target[person] = (rand() % 8 + 1) * 2 - 1; while (1) { if (create[person] == target[person]) target[person] = (rand() % 8 + 1) * 2 - 1; else break; } } if (create[person] < target[person])//행동정해줌 { act[person] = 1;//!!이때 person값과 create값을 floor에서 저장해주면? v1.plus_pget_up(create[person]); v1.plus_tget_up(target[person]); } else if (create[person]>target[person]) { act[person] = 2; v1.plus_pget_down(create[person]); v1.plus_tget_down(target[person]); } } void Passengers::produce_choose_oe(Floor &v1) { ++person; int a, b; while (1) { cout << "추가할 승객의 생성지,목적지를 입력해주세요" << endl; cin >> a >> b; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (a == b || (a == 2 * i || b == 2 * j - 1) || (a == 2 * i - 1 || b == 2 * i)) cout << "같은수&홀짝다르게 입력하셨습니다 다시입력해주세요" << endl; else break; } } } create[person] = a; target[person] = b; if (create[person] < target[person])//행동정해줌 { act[person] = 1;//!!이때 person값과 create값을 floor에서 저장해주면? v1.plus_pget_up(create[person]); v1.plus_tget_up(target[person]); } else if (create[person]>target[person]) { act[person] = 2; v1.plus_pget_down(create[person]); v1.plus_tget_down(target[person]); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #pragma once class Floor { private: int up_create[17]; //각층올라갈사람수 int down_create[17];//각층내려갈사람수 int up_target[17];//올라가는사람중 타켓인층 int down_target[17];//내려가는사람중 타켓인층 public: Floor()//초기설정 { for (int i = 0; i < 17; i++) { up_create[i] = 0; down_create[i] = 0; up_target[i] = 0; down_target[i] = 0; } } ~Floor() {}; int pget_up(int a)//private 값을 받기&리셋할수있게 { return up_create[a]; } int pget_down(int a) { return down_create[a]; } int tget_up(int a) { return up_target[a]; } int tget_down(int a) { return down_target[a]; } void minus_pget_up(int a, int b) { up_create[a] -= b; } void minus_pget_down(int a, int b) { down_create[a] -= b; } void plus_pget_up(int a) { ++up_create[a]; } void plus_pget_down(int a) { ++down_create[a]; } void plus_tget_up(int a) { ++up_target[a]; } void plus_tget_down(int a) { ++down_target[a]; } }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 | #pragma once void move_arrange(int a[]);//배열을 <<쪽으로 정리해주는 역할을해주는 함수 class Elevators { private: int present1;//현재 층 int present2; int destination1;//목적층 int destination2; int door_situation1;//문상태(문열림,닫힘)=(1/0) int door_situation2; int elevator_state1;//1.목적지없음 2.올라가는중 3.내려가는중 int elevator_state2; int people1[3];//[0]. 이전에 있던사람수, [1]. 탄후 바뀐 사람수, [2] 내린후 바뀐 사람수 int people2[3]; int take_passengers1[15]; int take_passengers2[15]; public: Elevators(int a = 0, int b = 0, int c = 16, int d = 16) :present1(a), destination1(b), present2(c), destination2(d) {//엘리베이터 초기상태 설정 door_situation1 = 0; door_situation2 = 0; elevator_state1 = 1; elevator_state2 = 1; for (int i = 0; i < 3; i++) { people1[i] = 0; people2[i] = 0; } for (int i = 0; i < 15; i++) { take_passengers1[i] = 0; take_passengers2[i] = 0; } } ~Elevators() {}; int get_present1() { return present1; } int get_present2() { return present2; } int get_destination1() { return destination1; } int get_destination2() { return destination2; } int get_elevator_state1() { return elevator_state1; } int get_elevator_state2() { return elevator_state2; } int get_door1() { return door_situation1; } int get_door2() { return door_situation2; } int get_people1() { return people1[0]; } int get_people2() { return people2[0]; } void set_destination1(int a) { destination1 = a; } void set_destination2(int a) { destination2 = a; } void set_door1() { door_situation1 = 0; } void set_door2() { door_situation2 = 0; } void Elevator_state();//엘리베이터 상태설정 void Elevator_move_take_in_out(Passengers &v1, Floor &v2);//엘리베이터 행동, 목적지설정 void go_create_n(Floor &v1);//생성지로 ㄱㄱ void go_target_n(Passengers &v1);//엘리베이터탄사람 목적지로 void take_in_out(Passengers &v1, Floor &v2);//엘리베이터 타고내림 void go_create_np(Floor &v1);//생성지로 ㄱㄱ void go_target_np(Passengers &v1);//엘리베이터탄사람 목적지로 void go_create_npp(Floor &v1);//생성지로 ㄱㄱ void go_target_npp(Passengers &v1);//엘리베이터탄사람 목적지로 void go_create_oe(Floor &v1); void take_in_out_oe(Passengers &v1, Floor &v2); void go_go(); }; void move_arrange(int a[])//배열을 <<쪽으로 정리해주는 역할을해주는 함수 { for (int i = 0; i < 15; i++) { for (int j = i; j < 15; j++) { if (a[j] == 0) { if (j == 14) ; else { a[j] = a[j + 1]; a[j + 1] = 0; } } } } } void Elevators::Elevator_state()//엘리베이터 상태설정 { if (destination1 > present1)//엘베1상태 elevator_state1 = 2; else if (destination1 < present1) elevator_state1 = 3; else if (destination1 == present1) elevator_state1 = 1; if (destination2 > present2)//엘베2상태 elevator_state2 = 2; else if (destination2 < present2) elevator_state2 = 3; else if (destination2 == present2) elevator_state2 = 1; } void Elevators::Elevator_move_take_in_out(Passengers &v1, Floor &v2)//엘리베이터 행동, 목적지설정 { if (elevator_state1 == 1)//목적지없음 { ; } else if (elevator_state1 == 2)//올라가는중 { if (people1[0] == people1[1] && people1[1] == people1[2])//손님없다면 present1++; else//손님이 있다면 { door_situation1 = 1;//문열어줌 } } else if (elevator_state1 == 3)//내려가는중 { if (people1[0] == people1[1] && people1[1] == people1[2])//손님없다면 present1--; else//손님이 있다면 { door_situation1 = 1;//문열어줌 } } //엘베2 if (elevator_state2 == 1)//목적지없음 { ; } else if (elevator_state2 == 2)//올라가는중 { if (people2[0] == people2[1] && people2[1] == people2[2])//손님없다면 present2++; else//손님이 있다면 { door_situation2 = 1;//문열어줌 } } else if (elevator_state2 == 3)//내려가는중 { if (people2[0] == people2[1] && people2[1] == people2[2])//손님없다면 present2--; else//손님이 있다면 { door_situation2 = 1;//문열어줌 } } people1[0] = people1[2]; people1[1] = people1[2]; people2[0] = people2[2]; people2[1] = people2[2]; } void Elevators::go_create_n(Floor &v1)//생성지로 ㄱㄱ { for (int i = 0; i < 17; i++) { if (elevator_state1 == 2) { if (i > present1) { if (v1.pget_up(i) != 0 && i > destination1) destination1 = i; if (v1.pget_down(i) != 0 && i > destination1) destination1 = i; } } else if (elevator_state1 == 1) { if (i > present1) { if (v1.pget_up(i) != 0 && i > destination1) destination1 = i; if (v1.pget_down(i) != 0 && i > destination1) destination1 = i; } else if (i < present1) { if (v1.pget_down(i) != 0 && i < destination1) destination1 = i; if (v1.pget_up(i) != 0 && i < destination1) destination1 = i; } } else if (elevator_state1 == 3) { if (i < present1) { if (v1.pget_down(i) != 0 && i < destination1) destination1 = i; if (v1.pget_up(i) != 0 && i < destination1) destination1 = i; } } // if (elevator_state2 == 2) { if (i > present2) { if (v1.pget_up(i) != 0 && i > destination2) destination2 = i; if (v1.pget_down(i) != 0 && i > destination2) destination2 = i; } } else if (elevator_state2 == 1) { if (i > present2) { if (v1.pget_up(i) != 0 && i > destination2) destination2 = i; if (v1.pget_down(i) != 0 && i > destination2) destination2 = i; } else if (i < present2) { if (v1.pget_down(i) != 0 && i < destination2) destination2 = i; if (v1.pget_up(i) != 0 && i < destination2) destination2 = i; } } else if (elevator_state2 == 3) { if (i < present2) { if (v1.pget_down(i) != 0 && i < destination2) destination2 = i; if (v1.pget_up(i) != 0 && i < destination2) destination2 = i; } } } } void Elevators::go_target_n(Passengers &v1) { if (elevator_state1 == 2) { if (people1[0] != 0) destination1 = 0; for (int i = 0; i < 15; i++) { if (take_passengers1[i] != 0) { if (destination1 < v1.get_target(take_passengers1[i])) destination1 = v1.get_target(take_passengers1[i]); } } } else if (elevator_state1 == 3) { for (int i = 0; i < 15; i++) { if (people1[0] != 0) destination1 = 16; if (take_passengers1[i] != 0) { if (destination1 > v1.get_target(take_passengers1[i])) destination1 = v1.get_target(take_passengers1[i]); } } } // if (elevator_state2 == 2) { if (people2[0] != 0) destination2 = 0; for (int i = 0; i < 15; i++) { if (take_passengers2[i] != 0) { if (destination2 < v1.get_target(take_passengers2[i])) destination2 = v1.get_target(take_passengers2[i]); } } } else if (elevator_state2 == 3) { if (people2[0] != 0) destination2 = 16; for (int i = 0; i < 15; i++) { if (take_passengers2[i] != 0) { if (destination2 > v1.get_target(take_passengers2[i])) destination2 = v1.get_target(take_passengers2[i]); } } } } void Elevators::take_in_out(Passengers &v1, Floor &v2) { for (int i = 0; i <= v1.get_person(); i++)//엘리베이터 타는부분 { if (present1 == v1.get_create(i))//타는것관련 엘베1옴 { if (elevator_state1 == 1)//도착후 정지인경우 안에 손님없다는뜻! { if (v1.get_act(i) == 1)//올라갈 손님~ { v2.minus_pget_up(present1, 1); take_passengers1[people1[1]] = i; v1.take_up(i); v1.set_act(i); people1[1]++; elevator_state1 = 2;//먼저온 위로올라갈사람이 먼저탔으니 엘리베이터를 위로올라가는상태로바꿔줌 } else if (v1.get_act(i) == 2)//내려갈 손님~ { v2.minus_pget_down(present1, 1); take_passengers1[people1[1]] = i; v1.take_up(i); v1.set_act(i); people1[1]++; elevator_state1 = 3; } } else if (elevator_state1 == 2)//위 { if (v1.get_act(i) == 1)//올라갈사람일때 { if (people1[1] < 15)//15명보다 적을때 더 탈수있음 { v2.minus_pget_up(present1, 1); take_passengers1[people1[1]] = i;//그사람이 누군지 저장 v1.take_up(i);//그 사람 탄상태로 v1.set_act(i); people1[1]++;//탄사람 증가 } } } else if (elevator_state1 == 3)//아래 { if (v1.get_act(i) == 2)//내려가는사람 { if (people1[1] < 15) { v2.minus_pget_down(present1, 1); take_passengers1[people1[1]] = i; v1.take_up(i); v1.set_act(i); people1[1]++; } } } } if (present2 == v1.get_create(i))//타는것관련 엘베2옴 { if (elevator_state2 == 1)//도착후 정지인경우 안에 손님없다는뜻! { if (v1.get_act(i) == 1)//올라갈 손님~ { v2.minus_pget_up(present2, 1); take_passengers2[people2[1]] = i; v1.take_up(i); v1.set_act(i); people2[1]++; elevator_state2 = 2;//먼저온 위로올라갈사람이 먼저탔으니 엘리베이터를 위로올라가는상태로바꿔줌 } else if (v1.get_act(i) == 2)//내려갈 손님~ { v2.minus_pget_down(present2, 1); take_passengers2[people2[1]] = i; v1.take_up(i); v1.set_act(i); people2[1]++; elevator_state2 = 3; } } else if (elevator_state2 == 2)//위 { if (v1.get_act(i) == 1)//올라갈사람일때 { if (people2[1] < 15)//15명보다 적을때 더 탈수있음 { v2.minus_pget_up(present2, 1); take_passengers2[people2[1]] = i;//그사람이 누군지 저장 v1.take_up(i);//그 사람 탄상태로 v1.set_act(i); people2[1]++;//탄사람 증가 } } } else if (elevator_state2 == 3)//아래 { if (v1.get_act(i) == 2)//내려가는사람 { if (people2[1] < 15) { v2.minus_pget_down(present2, 1); take_passengers2[people2[1]] = i; v1.set_act(i); v1.take_up(i); people2[1]++; } } } } } //내리는 부분 people1[2] = people1[1];//people[2]가 최종적인 손님수가 되도록 people2[2] = people2[1]; for (int i = 0; i < 15; i++) {//엘베1 if (present1 == v1.get_target(take_passengers1[i]) && v1.get_take(take_passengers1[i]) == 1)// 만약 타고있는사람의 목적지와 현재층이 같을때 { v1.take_down(take_passengers1[i]);//엘베내린거로 해줌 people1[2]--;//안에 사람줄음 take_passengers1[i] = 0; } //엘베2 if (present2 == v1.get_target(take_passengers2[i]) && v1.get_take(take_passengers2[i]) == 1) { v1.take_down(take_passengers2[i]); people2[2]--; take_passengers2[i] = 0; } } move_arrange(take_passengers1); move_arrange(take_passengers2); } void Elevators::go_create_np(Floor &v1)//생성지로 ㄱㄱ { for (int i = 0; i < 17; i++) { if (elevator_state1 == 2) { if (v1.pget_up(i) != 0 && i > destination1) destination1 = i; if (v1.pget_down(i) != 0 && i > destination1) destination1 = i; else if (elevator_state2 == 2) { if (v1.pget_up(i) != 0 && i > destination2) destination2 = i; if (v1.pget_down(i) != 0 && i > destination2) destination2 = i; } } if (elevator_state1 == 1) { if (i > present1) { if (v1.pget_up(i) != 0 && i > destination1) destination1 = i; if (v1.pget_down(i) != 0 && i > destination1) destination1 = i; } else if (i < present1) { if (v1.pget_down(i) != 0 && i < destination1) destination1 = i; if (v1.pget_up(i) != 0 && i < destination1) destination1 = i; } } else if (elevator_state2 == 1) { if (i > present2) { if (v1.pget_up(i) != 0 && i > destination2) destination2 = i; if (v1.pget_down(i) != 0 && i > destination2) destination2 = i; } else if (i < present2) { if (v1.pget_down(i) != 0 && i < destination2) destination2 = i; if (v1.pget_up(i) != 0 && i < destination2) destination2 = i; } } if (elevator_state1 == 3) { if (v1.pget_down(i) != 0 && i < destination1) destination1 = i; if (v1.pget_up(i) != 0 && i < destination1) destination1 = i; } else if (elevator_state2 == 3) { if (v1.pget_down(i) != 0 && i < destination2) destination2 = i; if (v1.pget_up(i) != 0 && i < destination2) destination2 = i; } } } void Elevators::go_target_np(Passengers &v1) { if (elevator_state1 == 2) { if (people1[0] != 0) destination1 = 0; for (int i = 0; i < 15; i++) { if (take_passengers1[i] != 0) { if (destination1 < v1.get_target(take_passengers1[i])) destination1 = v1.get_target(take_passengers1[i]); } } } else if (elevator_state1 == 3) { for (int i = 0; i < 15; i++) { if (people1[0] != 0) destination1 = 16; if (take_passengers1[i] != 0) { if (destination1 > v1.get_target(take_passengers1[i])) destination1 = v1.get_target(take_passengers1[i]); } } } // if (elevator_state2 == 2) { if (people2[0] != 0) destination2 = 0; for (int i = 0; i < 15; i++) { if (take_passengers2[i] != 0) { if (destination2 < v1.get_target(take_passengers2[i])) destination2 = v1.get_target(take_passengers2[i]); } } } else if (elevator_state2 == 3) { if (people2[0] != 0) destination2 = 16; for (int i = 0; i < 15; i++) { if (take_passengers2[i] != 0) { if (destination2 > v1.get_target(take_passengers2[i])) destination2 = v1.get_target(take_passengers2[i]); } } } } void Elevators::go_create_npp(Floor &v1)//생성지로 ㄱㄱ { for (int i = 0; i < 8; i++) { if (elevator_state1 == 2) { if (i > present1) { if (v1.pget_up(i) != 0 && i > destination1) destination1 = i; if (v1.pget_down(i) != 0 && i > destination1) destination1 = i; } } else if (elevator_state1 == 1) { if (i > present1) { if (v1.pget_up(i) != 0 && i > destination1) destination1 = i; if (v1.pget_down(i) != 0 && i > destination1) destination1 = i; } else if (i < present1) { if (v1.pget_down(i) != 0 && i < destination1) destination1 = i; if (v1.pget_up(i) != 0 && i < destination1) destination1 = i; } } else if (elevator_state1 == 3) { if (i < present1) { if (v1.pget_down(i) != 0 && i < destination1) destination1 = i; if (v1.pget_up(i) != 0 && i < destination1) destination1 = i; } } } // for (int i = 8; i < 17; i++) { if (elevator_state2 == 2) { if (i > present2) { if (v1.pget_up(i) != 0 && i > destination2) destination2 = i; if (v1.pget_down(i) != 0 && i > destination2) destination2 = i; } } else if (elevator_state2 == 1) { if (i > present2) { if (v1.pget_up(i) != 0 && i > destination2) destination2 = i; if (v1.pget_down(i) != 0 && i > destination2) destination2 = i; } else if (i < present2) { if (v1.pget_down(i) != 0 && i < destination2) destination2 = i; if (v1.pget_up(i) != 0 && i < destination2) destination2 = i; } } else if (elevator_state2 == 3) { if (i < present2) { if (v1.pget_down(i) != 0 && i < destination2) destination2 = i; if (v1.pget_up(i) != 0 && i < destination2) destination2 = i; } } } } void Elevators::go_target_npp(Passengers &v1) { if (elevator_state1 == 2) { if (people1[0] != 0) destination1 = 0; for (int i = 0; i < 15; i++) { if (take_passengers1[i] != 0) { if (destination1 < v1.get_target(take_passengers1[i])) destination1 = v1.get_target(take_passengers1[i]); } } } else if (elevator_state1 == 3) { for (int i = 0; i < 15; i++) { if (people1[0] != 0) destination1 = 16; if (take_passengers1[i] != 0) { if (destination1 > v1.get_target(take_passengers1[i])) destination1 = v1.get_target(take_passengers1[i]); } } } // if (elevator_state2 == 2) { if (people2[0] != 0) destination2 = 0; for (int i = 0; i < 15; i++) { if (take_passengers2[i] != 0) { if (destination2 < v1.get_target(take_passengers2[i])) destination2 = v1.get_target(take_passengers2[i]); } } } else if (elevator_state2 == 3) { if (people2[0] != 0) destination2 = 16; for (int i = 0; i < 15; i++) { if (take_passengers2[i] != 0) { if (destination2 > v1.get_target(take_passengers2[i])) destination2 = v1.get_target(take_passengers2[i]); } } } } void Elevators::go_create_oe(Floor &v1)//생성지로 ㄱㄱ { for (int i = 0; i < 9; i++) { if (elevator_state1 == 2) { if (2 * i > present1) { if (v1.pget_up(2 * i) != 0 && 2 * i > destination1) destination1 = 2 * i; if (v1.pget_down(2 * i) != 0 && 2 * i > destination1) destination1 = 2 * i; } } else if (elevator_state1 == 1) { if (2 * i > present1) { if (v1.pget_up(2 * i) != 0 && 2 * i > destination1) destination1 = 2 * i; if (v1.pget_down(2 * i) != 0 && 2 * i > destination1) destination1 = 2 * i; } else if (2 * i < present1) { if (v1.pget_down(2 * i) != 0 && 2 * i < destination1) destination1 = 2 * i; if (v1.pget_up(2 * i) != 0 && 2 * i < destination1) destination1 = 2 * i; } } else if (elevator_state1 == 3) { if (2 * i < present1) { if (v1.pget_down(2 * i) != 0 && 2 * i < destination1) destination1 = 2 * i; if (v1.pget_up(2 * i) != 0 && i < destination1) destination1 = 2 * i; } } } /// for (int i = 1; i < 9; i++) { if (elevator_state2 == 2) { if (2 * i - 1 > present2) { if (v1.pget_up(2 * i - 1) != 0 && 2 * i - 1 > destination2) destination2 = 2 * i - 1; if (v1.pget_down(2 * i - 1) != 0 && 2 * i - 1 > destination2) destination2 = 2 * i - 1; } } else if (elevator_state2 == 1) { if (2 * i - 1 > present2) { if (v1.pget_up(2 * i - 1) != 0 && 2 * i - 1 > destination2) destination2 = 2 * i - 1; if (v1.pget_down(2 * i - 1) != 0 && 2 * i - 1 > destination2) destination2 = 2 * i - 1; } else if (2 * i - 1 < present2) { if (v1.pget_down(2 * i - 1) != 0 && 2 * i - 1 < destination2) destination2 = 2 * i - 1; if (v1.pget_up(2 * i - 1) != 0 && 2 * i - 1 < destination2) destination2 = 2 * i - 1; } } else if (elevator_state2 == 3) { if (2 * i - 1 < present2) { if (v1.pget_down(2 * i - 1) != 0 && 2 * i - 1 < destination2) destination2 = 2 * i - 1; if (v1.pget_up(2 * i - 1) != 0 && 2 * i - 1 < destination2) destination2 = 2 * i - 1; } } } } void Elevators::take_in_out_oe(Passengers &v1, Floor &v2) { for (int i = 0; i <= v1.get_person(); i++)//엘리베이터 타는부분 { if (present1 == v1.get_create(i) && (present1 == 0 || present1 == 2 || present1 == 4 || present1 == 6 || present1 == 8 || present1 == 10 || present1 == 12 || present1 == 14 || present1 == 16))//타는것관련 엘베1옴 { if (elevator_state1 == 1)//도착후 정지인경우 안에 손님없다는뜻! { if (v1.get_act(i) == 1)//올라갈 손님~ { v2.minus_pget_up(present1, 1); take_passengers1[people1[1]] = i; v1.take_up(i); v1.set_act(i); people1[1]++; destination1 = v1.get_target(i); elevator_state1 = 2;//먼저온 위로올라갈사람이 먼저탔으니 엘리베이터를 위로올라가는상태로바꿔줌 } else if (v1.get_act(i) == 2)//내려갈 손님~ { v2.minus_pget_down(present1, 1); take_passengers1[people1[1]] = i; v1.take_up(i); v1.set_act(i); people1[1]++; destination1 = v1.get_target(i); elevator_state1 = 3; } } else if (elevator_state1 == 2)//위 { if (v1.get_act(i) == 1)//올라갈사람일때 { if (people1[1] < 15)//15명보다 적을때 더 탈수있음 { v2.minus_pget_up(present1, 1); take_passengers1[people1[1]] = i;//그사람이 누군지 저장 v1.take_up(i);//그 사람 탄상태로 v1.set_act(i); people1[1]++;//탄사람 증가 if (v1.get_target(i) > destination1) destination1 = v1.get_target(i);//목적지가 더크면 바꿔줌 } } } else if (elevator_state1 == 3)//아래 { if (v1.get_act(i) == 2)//내려가는사람 { if (people1[1] < 15) { v2.minus_pget_down(present1, 1); take_passengers1[people1[1]] = i; v1.take_up(i); v1.set_act(i); people1[1]++; if (v1.get_target(i) < destination1) destination1 = v1.get_target(i);//목적지가 더작으면 바꿔줌 } } } } if (present2 == v1.get_create(i) && (present2 == 1 || present2 == 3 || present2 == 5 || present2 == 7 || present2 == 9 || present2 == 11 || present2 == 13 || present2 == 15))//타는것관련 엘베2옴 { if (elevator_state2 == 1)//도착후 정지인경우 안에 손님없다는뜻! { if (v1.get_act(i) == 1)//올라갈 손님~ { v2.minus_pget_up(present2, 1); take_passengers2[people2[1]] = i; v1.take_up(i); v1.set_act(i); people2[1]++; destination2 = v1.get_target(i); elevator_state2 = 2;//먼저온 위로올라갈사람이 먼저탔으니 엘리베이터를 위로올라가는상태로바꿔줌 } else if (v1.get_act(i) == 2)//내려갈 손님~ { v2.minus_pget_down(present2, 1); take_passengers2[people2[1]] = i; v1.take_up(i); v1.set_act(i); people2[1]++; destination2 = v1.get_target(i); elevator_state2 = 3; } } else if (elevator_state2 == 2)//위 { if (v1.get_act(i) == 1)//올라갈사람일때 { if (people2[1] < 15)//15명보다 적을때 더 탈수있음 { v2.minus_pget_up(present2, 1); take_passengers2[people2[1]] = i;//그사람이 누군지 저장 v1.take_up(i);//그 사람 탄상태로 v1.set_act(i); people2[1]++;//탄사람 증가 if (v1.get_target(i) > destination2) destination2 = v1.get_target(i);//목적지가 더크면 바꿔줌 } } } else if (elevator_state2 == 3)//아래 { if (v1.get_act(i) == 2)//내려가는사람 { if (people2[1] < 15) { v2.minus_pget_down(present2, 1); take_passengers2[people2[1]] = i; v1.set_act(i); v1.take_up(i); people2[1]++; if (v1.get_target(i) < destination1) destination1 = v1.get_target(i);//목적지가 더작으면 바꿔줌 } } } } } //내리는 부분 people1[2] = people1[1];//people[2]가 최종적인 손님수가 되도록 people2[2] = people2[1]; for (int i = 0; i < 15; i++) {//엘베1 if (present1 == v1.get_target(take_passengers1[i]) && v1.get_take(take_passengers1[i]) == 1)// 만약 타고있는사람의 목적지와 현재층이 같을때 { v1.take_down(take_passengers1[i]);//엘베내린거로 해줌 people1[2]--;//안에 사람줄음 take_passengers1[i] = 0; } //엘베2 if (present2 == v1.get_target(take_passengers2[i]) && v1.get_take(take_passengers2[i]) == 1) { v1.take_down(take_passengers2[i]); people2[2]--; take_passengers2[i] = 0; } } move_arrange(take_passengers1); move_arrange(take_passengers2); } void Elevators::go_go()//목적지는 지하2~15층 와리가리 { if (destination1 == 16) { if (present1 == 16) destination1 = 0; } else if (destination1 == 0) { if (present1 == 0) destination1 = 16; } //// if (destination2 == 16) { if (present2 == 16) destination2 = 0; } else if (destination2 == 0) { if (present2 == 0) destination2 = 16; } } |
소스다운하기 vs2015
elevator_combine_5second.vol1.egg
elevator_combine_5second.vol2.egg
반응형
'Coding Challenge' 카테고리의 다른 글
[소스공유] C언어로 만든 지뢰찾기 (2) | 2017.05.24 |
---|---|
[소스공유/JAVA] KBO야구경기 시뮬레이션 (0) | 2017.04.29 |
[소스공유/c언어] 후위연산자 계산기 (2) | 2017.04.29 |
[소스공유/C언어] 다항식 연산 프로그램 (1) | 2017.04.29 |
프로그래밍 공부법 (코딩 실력 늘리기) (9) | 2017.04.29 |