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 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <conio.h> #include <string.h> char solutions[4][100] = { "meet at midnight","hello C world", "good luck to you", "merry cristmas" }; int main(void) { char *solution; // Á¤´äÀÌ µé¾î ÀÖ´Â ¹®ÀÚ ¹è¿ char answer[100]; // ÇöÀç±îÁö »ç¿ëÀÚ°¡ ¸ÂÃá ¹®ÀÚ¿ char ch; int i, n; srand(time(NULL)); n = rand() % 4; solution = solutions[n]; for (i = 0; i < strlen(solution); i++) { if (solution[i] == ' ') answer[i] = ' '; else answer[i] = '_'; } answer[i] = '\0'; while (1) { printf("\n¹®ÀÚ¿À» ÀÔ·ÂÇϽÿÀ: %s \n", answer); printf("±ÛÀÚ¸¦ ÃßÃøÇϽÿÀ: "); ch = _getch(); // »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ ¹®ÀÚ¸¦ answer[]¿¡ ³Ö¾î¼ Á¤´äÀ» ºñ±³ÇÑ´Ù. for (i = 0; solution[i] != '\0'; i++) { // »ç¿ëÀÚ°¡ ¸ÂÃß¾úÀ¸¸é ±ÛÀÚ¸¦ º¸ÀÌ°Ô ÇÑ´Ù. if (solution[i] == ch) answer[i] = ch; } if (strcmp(solution, answer) == 0) break; // Á¤´ä°ú ÀÏÄ¡ÇÏ´ÂÁö¸¦ °Ë»ç } return 0; } | cs |