일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- html charset
- border-box
- #JAVASCRIPT
- html id
- docker example
- #binary
- #2차원배열
- #bubbleSort
- #자바상속#자바이즈어#is~a
- relative path
- html video
- git flow
- #CallByAddress
- #1차원배열
- html5 new tag
- #3차원배열
- html youtube
- #android activity
- html object
- #C++ has~a
- html multimedia
- hyperledger transaction
- mac terminal command
- #C++ 연산자함수오버로딩
- 하이퍼레저패브릭
- #성적관리프로그램
- html plug-in
- 토큰경제
- #다차원포인터
- html code
- Today
- Total
A sentimental robot
Baseball Game(computer vs user) 본문
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#pragma warning(disable:4996)
void random(int r[]);
void ansGuessing(int g[], int a);
void ansChecking(int g[], int r[]);
void main()
{
int r[3];
int g[3];
int a = 0;
do {
random(r);
ansGuessing(g, a);
ansChecking(g, r);
} while (1);
}
void random(int r[]) {
int i;
srand((unsigned int)time(NULL));
for (i = 0; i < 3; i++)
{
r[i] = rand() % 10;
while (r[0] == r[1] || r[1] == r[2] || r[0] == r[2]) {
i = 0; // 다시 for문으로 들어가게 만들기
break;
}
}
printf("%d\t%d\t%d\n", r[0], r[1], r[2]);
}
void ansGuessing(int g[], int a) {
do {
printf("Attack (3 num) :");
rewind(stdin);
scanf("%d", &a);
g[0] =( a / 100);
g[1] = (a / 10) % 10;
g[2] = a % 10;
if (g[0] == g[1] || g[1] == g[2] || g[0] == g[2]) printf("Re-input\n");
} while (g[0]==g[1]||g[1]==g[2]||g[0]==g[2]);
}
void ansChecking(int g[], int r[]) {
int ballCount=0;
int strikeCount=0;
int i, j = 0;
for (i = 0; i < 3; i++) {
if ( g[i] == r[i] ) { strikeCount++;continue; }
for (j = 0; j < 3; j++) {
if ( g[i] == r[j] )ballCount++;
}
}
printf("ball:%d\t strike:%d\n", ballCount, strikeCount);
if (strikeCount == 3) printf("Win!!!!!!\n");
}
'Data Structure' 카테고리의 다른 글
Linear Queue (0) | 2018.01.03 |
---|---|
Babygin (0) | 2018.01.03 |
Single LinkedList Exercise2 (0) | 2018.01.03 |
Single LinkedList Exercise (0) | 2018.01.03 |
LinkedList (0) | 2018.01.03 |