{"id":2236,"date":"2009-10-02T09:50:04","date_gmt":"2009-10-02T09:50:04","guid":{"rendered":"http:\/\/192.168.0.71:9090\/?p=1938"},"modified":"2009-10-02T09:50:04","modified_gmt":"2009-10-02T09:50:04","slug":"programming-challenges-%ea%b7%b8%eb%9e%98%ed%94%bd-%ed%8e%b8%ec%a7%91%ea%b8%b0-graphical-editor","status":"publish","type":"post","link":"https:\/\/talsu.net\/?p=2236","title":{"rendered":"Programming Challenges &#8211; \uadf8\ub798\ud53d \ud3b8\uc9d1\uae30 (Graphical Editor)"},"content":{"rendered":"<p><span style=\"font-size: 12pt; font-weight: bold;\"><a title=\"[http:\/\/programming-challenges.com\/pg.php?page=downloadproblem&amp;probid=110105&amp;format=html]\ub85c \uc774\ub3d9\ud569\ub2c8\ub2e4.\" target=\"_blank\" href=\"http:\/\/programming-challenges.com\/pg.php?page=downloadproblem&amp;probid=110105&amp;format=html\">\ubb38\uc81c &lt;- \ud074\ub9ad<\/a><\/span><\/p>\n<p>\uc544\ubb34\ub9ac \uccb4\ud06c\ud574\ubd10\ub3c4 \ub2f5\uc774 \ub9de\ub294\ub370 \ud2c0\ub838\ub2e4\uace0 \ud55c\ub2e4&#8230; \ub108\ubb34 \uc774\uc0c1\ud574\uc11c \ucc45\uc758 \ubaa8\ubc94\ub2f5\uc548\uc744 \ub611\uac19\uc774 \uc801\uc5b4 \uc81c\ucd9c \ud588\ub354\ub2c8 \uadf8\ub798\ub3c4 \ud2c0\ub838\ub2e4\uace0 \ud55c\ub2e4;; <br \/>\n\ucc44\uc810 \ub85c\ubd07\uc5d0 \ubb54\uac00 \ubb38\uc81c\uac00 \uc788\ub294\uac74\uc9c0&#8230; \uc544\uc624 \uc5f4\ubc1b\uc544..\uc2dc\uac04\ub3c4 \uc544\uae5d\uace0.. <\/p>\n<pre class=\"lang:c++ decode:true\">#include <iostream>\n#include <string>\n#include <limits>\n\n#define MAXNM 250\nusing namespace std;\n\nclass GraphicalEditor {\nprivate:\n\tchar field[MAXNM + 1][MAXNM + 1];\n\tint m, n;\n\n\tbool isValid(int x, int y) {\n\t\tif (1 <= x &#038;&#038; x <= m &#038;&#038; 1 <= y &#038;&#038; y <= n)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tchar getPixel(int x, int y) {\n\t\tif (isValid(x, y))\n\t\t\treturn field[y - 1][x - 1];\n\t\treturn -1;\n\t}\n\n\tvoid L_setPixel(int x, int y, char color) {\n\t\tif (isValid(x, y))\n\t\t\tfield[y - 1][x - 1] = color;\n\t}\n\n\tvoid V_verticalLine(int x, int y1, int y2, char color) {\n\n\t\tint high = std::max(y1, y2);\n\t\tint low = std::min(y1, y2);\n\n\t\tfor (int i = low; i <= high; ++i) {\n\t\t\tL_setPixel(x, i, color);\n\t\t}\n\t}\n\n\tvoid H_horizonLine(int x1, int x2, int y, char color) {\n\t\tint high = std::max(x1, x2);\n\t\tint low = std::min(x1, x2);\n\n\t\tfor (int i = low; i <= high; ++i) {\n\t\t\tL_setPixel(i, y, color);\n\t\t}\n\t}\n\n\tvoid K_square(int x1, int y1, int x2, int y2, char color) {\n\t\tint highX = std::max(x1, x2);\n\t\tint lowX = std::min(x1, x2);\n\t\tint highY = std::max(y1,y2);\n\t\tint lowY = std::min(y1,y2);\n\t\tfor( int i = lowX; i<=highX; ++i){\n\t\t\tfor(int j = lowY; j <= highY; ++j){\n\t\t\t\tL_setPixel(i,j,color);\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid C_clear() {\n\t\tfor (int i = 0; i < MAXNM + 1; ++i) {\n\t\t\tfor (int j = 0; j < MAXNM + 1; ++j) {\n\t\t\t\tfield[i][j] = 'O';\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid F_fill(int x, int y, char color) {\n\t\tif (!isValid(x, y))\n\t\t\treturn;\n\t\tint ninusX = x - 1;\n\t\tint plusX = x + 1;\n\t\tint ninusY = y - 1;\n\t\tint plusY = y + 1;\n\t\tchar oldColor = getPixel(x, y);\n\t\t\/\/\tfield[y - 1][x - 1] = color;\n\t\tL_setPixel(x, y, color);\n\n\t\tif (isValid(ninusX, y) &#038;&#038; (getPixel(ninusX, y) == oldColor))\n\t\t\tF_fill(ninusX, y, color);\n\t\tif (isValid(x, ninusY) &#038;&#038; (getPixel(x, ninusY) == oldColor))\n\t\t\tF_fill(x, ninusY, color);\n\t\tif (isValid(plusX, y) &#038;&#038; (getPixel(plusX, y) == oldColor))\n\t\t\tF_fill(plusX, y, color);\n\t\tif (isValid(x, plusY) &#038;&#038; (getPixel(x, plusY) == oldColor))\n\t\t\tF_fill(x, plusY, color);\n\n\t}\n\n\tvoid S_saveAndPrint(string&#038; name) {\n\t\tcout << name << endl;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tcout<<field[i][j];\n\t\t\t}\n\t\t\tcout<<endl;\n\t\t}\n\t}\n\npublic:\n\texplicit GraphicalEditor() {\n\t}\n\n\tint inputCommand(char command) {\n\t\tstring fileName;\n\t\tchar charArg;\n\t\tint intArg[5];\n\t\tswitch (command) {\n\t\tcase 'I':\n\t\t\tcin >> m >> n;\n\t\tcase 'C':\n\t\t\tC_clear();\n\t\t\tbreak;\n\t\tcase 'L':\n\t\t\tcin >> intArg[0] >> intArg[1] >> charArg;\n\t\t\tL_setPixel(intArg[0], intArg[1], charArg);\n\t\t\tbreak;\n\t\tcase 'V':\n\t\t\tcin >> intArg[0] >> intArg[1] >> intArg[2] >> charArg;\n\t\t\tV_verticalLine(intArg[0], intArg[1], intArg[2], charArg);\n\t\t\tbreak;\n\t\tcase 'H':\n\t\t\tcin >> intArg[0] >> intArg[1] >> intArg[2] >> charArg;\n\t\t\tH_horizonLine(intArg[0], intArg[1], intArg[2], charArg);\n\t\t\tbreak;\n\t\tcase 'K':\n\t\t\tcin >> intArg[0] >> intArg[1] >> intArg[2] >> intArg[3] >> charArg;\n\t\t\tK_square(intArg[0], intArg[1], intArg[2], intArg[3], charArg);\n\t\t\tbreak;\n\t\tcase 'F':\n\t\t\tcin >> intArg[0] >> intArg[1] >> charArg;\n\t\t\tF_fill(intArg[0], intArg[1], charArg);\n\t\t\tbreak;\n\t\tcase 'S':\n\t\t\tcin >> fileName;\n\t\t\tS_saveAndPrint(fileName);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tstd::cin.ignore( std::numeric_limits<std::streamsize>::max(), 'n' );\n\t\t\tbreak;\n\t\t}\n\t\treturn 1;\n\t}\n\n};\n\nint main() {\n\n\tchar command = 0;\n\tGraphicalEditor ge;\n\n\twhile ((cin >> command) && command != 'X') {\n\t\tif(!ge.inputCommand(command))\n\t\t\tbreak;\n\t}\n\treturn 0;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ubb38\uc81c &lt;- \ud074\ub9ad \uc544\ubb34\ub9ac \uccb4\ud06c\ud574\ubd10\ub3c4 \ub2f5\uc774 \ub9de\ub294\ub370 \ud2c0\ub838\ub2e4\uace0 \ud55c\ub2e4&#8230; \ub108\ubb34 \uc774\uc0c1\ud574\uc11c \ucc45\uc758 \ubaa8\ubc94\ub2f5\uc548\uc744 \ub611\uac19\uc774 \uc801\uc5b4 \uc81c\ucd9c \ud588\ub354\ub2c8 \uadf8\ub798\ub3c4 \ud2c0\ub838\ub2e4\uace0 \ud55c\ub2e4;; \ucc44\uc810 \ub85c\ubd07\uc5d0 \ubb54\uac00 \ubb38\uc81c\uac00 \uc788\ub294\uac74\uc9c0&#8230; \uc544\uc624 \uc5f4\ubc1b\uc544..\uc2dc\uac04\ub3c4 \uc544\uae5d\uace0.. #include #include #include #define MAXNM 250 using namespace std; class GraphicalEditor { private: char field[MAXNM + 1][MAXNM + 1]; int m, n; bool isValid(int x, int y) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[9],"tags":[49,131,203,303],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pXV5a-A4","_links":{"self":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/2236"}],"collection":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2236"}],"version-history":[{"count":0,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/2236\/revisions"}],"wp:attachment":[{"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}