#include <stdio.h>#include <stdlib.h>#include <time.h>
void randomAnswer(int ans[]) { for (int i = 0; i < 4; i++) { ans[i] = rand() % 10; for (int j = 0; j < i; j++) { if (ans[j] == ans[i]) { i--; break; } } }}
int main(void) { int ans[4], num[4]; int strike, ball, steps; int reset; srand(time(NULL));
while (1) { printf("»õ °ÔÀÓÀÔ´Ï´Ù.\n"); steps = 1; reset = 1; randomAnswer(ans); for (int i = 0; i < 4; i++) { printf("%d", ans[i]); } printf("\n"); while (reset) { strike = 0, ball = 0; printf("(%d)> ", steps); scanf("%d %d %d %d", &num[0], &num[1], &num[2], &num[3]); for (int j = 0; j < 4; j++) { if (ans[j] == num[j]) strike++; else { for (int k = 0; k < 4; k++) { if (num[j] == ans[k]) { ball++; break; } } } } if (strike == 4) { printf("ÃàÇÏÇÕ´Ï´Ù. %d½ºÅܸ¸¿¡ ¸ÂÃß¾ú½À´Ï´Ù\n\n", steps); reset = 0; } else { printf("\t\t(%d ½ºÆ®¶óÀÌÅ© %d º¼)\n", strike, ball); steps++; } } }}