= ë ˆì´íŠ¼ êµìˆ˜ì™€ 함께 하는 CodeRace = * PairProgramming * 1,2학년-3,4í•™ë…„ì´ í•œ íŒ€ì„ ì´ë£¬ë‹¤. * ë‘ëª…ì´ í•˜ë‚˜ì˜ ëª¨ë‹ˆí„°ë¥¼ ë³´ê³ í•˜ë‚˜ì˜ í‚¤ë³´ë“œë¡œ í”„ë¡œê·¸ëž˜ë° í•´ì•¼ 한다. * ì—í• * Navigator : Driverì—게 어떻게 í•´ì•¼í• ì§€ ì•Œë ¤ì£¼ëŠ” ì—í• . 키보드를 ì§ì ‘ 잡지 않는다. * Driver : Navigatorê°€ ì•Œë ¤ì£¼ëŠ”ëŒ€ë¡œ ì‹¤ì œ 코딩하는 ì—í• . Navigatorì˜ ì§€ì‹œ ì—†ì´ í˜¼ìž ì½”ë”©í•˜ì§€ 않는다. * 3분마다 ì—í• ì„ ë°”ê¾¸ëŠ”ë° ìŠ¤ìœ„ì¹˜ ëª¨ì…˜ì„ ì·¨í•œ ë’¤ ìžë¦¬ë¥¼ 바꿔야 한다. * ë°°ê²½ * A마ì„ê³¼ Bë§ˆì„ ì‚¬ì´ì—는 ê°•ì´ ìžˆë‹¤. * 배를 타지 ì•Šê³ ê°•ì„ ê±´ë„ ìˆ˜ 없다. * 등장하는 ëª¨ë“ ì¸ë¬¼ì´ ê°•ì„ ê±´ë„ˆ 다른 마ì„ë¡œ 가야한다. * 진행 1. ë ˆì´íŠ¼ êµìˆ˜ê°€ A마ì„ì—ì„œ 배를 íƒ€ê³ ê°•ì„ ê±´ë„ˆ B마ì„ë¡œ 간다. 1. ë ˆì´íŠ¼ êµìˆ˜ê°€ A마ì„ì— ìžˆë‹¤ë©´ B마ì„ë¡œ, B마ì„ì— ìžˆë‹¤ë©´ A마ì„ë¡œ 간다. 1. 루í¬ì˜ 등장 1. 루í¬ëŠ” ì–´ë ¤ì„œ 혼ìžì„œëŠ” 배를 탈 수 없다. 1. ë‚˜ìœ ì•„ì €ì”¨ 등장 1. ë‚˜ìœ ì•„ì €ì”¨ëŠ” ë ˆì´íŠ¼ êµìˆ˜ê°€ 없으면 루í¬ë¥¼ ê°•ì— ë˜ì ¸ë²„린다. 1. ì•Œê³ ë³´ë‹ˆ ë°°ê°€ 2ì¸ìŠ¹ì´ì—ˆë‹¤. * ë‚´ê°€ ì´ê±¸ 진행ìƒí™©ì„ 다 ì•Œê³ ë‹¤ì‹œ 프로그래ë°í•œë‹¤ë©´... * [ì •ëª¨/2011.4.4/CodeRace/강소현] == ì“°ë ˆê¸° == {{{ public class person { static private String name = ""; static boolean isOnShip; public String city; public person(String name){this.name = name;} public void moveCity(){ // A->B, B->A if(isOnShip != true) return; if(city == "A"){ city = "B"; }else if(city == "B"){ city = "A"; } isOnShip = false; System.out.println(name + "ì€/는 지금 "+city+"ì—있다"); } } }}} {{{ public class Raton { private static String city = "A"; public static void main(String[] args) { // A -> B // System.out.println(city); // city = "B"; // System.out.println(city); // // // A->B, B->A // if(city == "A"){ // city = "B"; // }else if(city == "B"){ // city = "A"; // } // System.out.println(city); // // 2ì¸ìŠ¹ ë°° person Luke = new person("루í¬"); person Raton = new person("ë ˆì´íŠ¼"); person Bad = new person("나ìœì•„ì €ì”¨"); Luke.city = "A"; Raton.city = "A"; Bad.city = "A"; Luke.isOnShip = true; Raton.isOnShip = true; Luke.moveCity(); Raton.moveCity(); Raton.moveCity(); } } }}} == 핸드í°ì´ 죽었슴다 == {{{ #include<iostream> using namespace std; void main(){ char location1 = 'A'; char location2 = 'A'; char location3 = 'A'; while (1) { cout << "ë ˆì´íŠ¼ì˜ 현재 위치 " << location1 << endl; cout << "루í¬ì˜ 현재 위치 " << location2 << endl; cout << "ë‚˜ìœ ì•„ì €ì”¨ì˜ í˜„ìž¬ 위치 " << location3 << endl; int i1 = -1, i2 = -1; cout << "ë°°ì— íƒˆ 사람ì€? (ë ˆì´íŠ¼:1, 루í¬:2, 나ìœì•„ì €ì”¨:3, ë:0) "; cin >> i1; cin >> i2; if(i1 == 1 && i2 == 2){ location1 = location1=='B'?'A':'B'; location2 = location2=='B'?'A':'B'; } if (i1 == 2 && i2 == 3){ location2 = location2=='B'?'A':'B'; location3 = location3=='B'?'A':'B'; } if (i1 == 1 && i2 == 3){ location1 = location1=='B'?'A':'B'; location3 = location3=='B'?'A':'B'; } if (i1 == 1 && i2 == 0) location1 = location1=='B'?'A':'B'; if (i1 == 2 && i2 == 0) location2 = location2=='B'?'A':'B'; if (i1 == 3 && i2 == 0) location3 = location3=='B'?'A':'B'; if (location1 != location2 && location2 == location3) { cout << "루í¬ê°€ 죽었슴다 ã…¡ã…¡" << endl; return; } cout << endl; } } }}} == Untitled.txt == {{{ #include <stdio.h> typedef struct _h { int id; } human; typedef struct _t { human h[3]; } town; int main(int argc, const char **argv) { human raten, ruke, bad, pl1, pl2, pl3; town a, b; a.h[0] = raten; a.h[1] = ruke; a.h[2] = bad; b.h[0] =a.h[0]; b.h[1]=a.h[1]; a.h[0]=pl1; a.h[1]=pl2; a.h[0]=b.h[0]; b.h[0]=pl1; b.h[0]=a.h[0]; b.h[2]=a.h[2]; a.h[0]=pl1; a.h[2]=pl3; return 0; } }}} == 기ìƒì¶© == {{{ public class Ship { public int maxNum; public int cur; public Ship(int n){ maxNum = n; cur = 0; } public void take(){ cur++; } public void getOff(){ cur--; } public boolean cross(){ return (maxNum >= cur); } } }}} {{{ public class BadUncle { public boolean location; public BadUncle(){location = true;} public void ThrowRook(ProfessorR r, Child c) { if( r.location != c.location && location == c.location ) killRook(); } public void crossRiver() { if(location) location = false; else location = true; } public void printLocation() { String str = (location)? "A" : "B"; System.out.println("Uncle loc : " + str); } private void killRook() { System.out.println("ë£¨í¬ ì£½ìŒ ã…‹"); } } }}} {{{ public class Child { public boolean location; public Child() { location = true; } public void crossRiver(ProfessorR r) { if( r.location == location ) { if(location) { location = false; r.location = false; } else { location = true; r.location = true; } } } public void printLocation() { String str = (location)? "A" : "B"; System.out.println("Child loc : " + str); } } }}} {{{ public class ProfessorR { public boolean location; public ProfessorR() { location = true; } public void crossRiver() { if(location) location = false; else location = true; } public void printLocation() { String str = (location)? "A" : "B"; System.out.println("Professor loc : " + str); } public static void main(String[] args) { ProfessorR test = new ProfessorR(); Child rook = new Child(); test.printLocation(); test.crossRiver(); test.printLocation(); test.crossRiver(); test.printLocation(); rook.printLocation(); rook.crossRiver(test); rook.printLocation(); test.printLocation(); BadUncle b = new BadUncle(); test.crossRiver(); b.crossRiver(); test.printLocation(); b.printLocation(); rook.printLocation(); b.ThrowRook(test, rook); } } }}} ---- [ì •ëª¨/2011.4.4]