숫자야구 ---- {{{~cpp #include // 랜덤함수는 iostream에 포함되어 있습니다. #include // time(0)의 사용을 위해 필요합니다. using namespace std; void main() { // srand(time(0)); // rand()의 시드값을 설정합니다. // 하지 않으면 실행할때마다 같은값을 만듭니다. -_-;; // int x = rand(); // rand()함수는 랜덤한 숫자를 리턴하는 함수입니다. // 리턴하는 숫자의 범위는 0 ~ 무지무지 큰 수 입니다. // int x1 = rand() % 10; // % 10 연산을 하면 x1 에는 10의 나머지가 될 수 있는 // 0 ~ 9 까지의 숫자가 랜덤하게 들어갑니다. // int x2 = rand() % 9 + 1; // % 9를 하면 0~9까지의 숫자가 들어갈 수 있고 // 거기에 1을 더하면 1~10 까지의 숫자가 됩니다. cout << "세자리 숫자를 입력하세요 : " << endl; srand(time(0)); int x; int a[3]; do { x = rand() % 1000; a[0] = x/100; a[1] = (x-(a[0]*100))/10; a[2] = (x-(a[0]*100)-(a[1]*10))/1; }while(a[0]==a[1]||a[1]==a[2]||a[0]==a[2]); cout << a[0]<> soo; int c[3]; c[0] = soo/100; c[1] = (soo-(c[0]*100))/10; c[2] = (soo-(c[0]*100)-(c[1]*10))/1; int i; int count =0; int count2=0; for(i=0; i<3; i++) { if (a[i] == c[i]) count++ ; } cout << count << " strike"<<"\t"; if (a[0]==c[1]) count2++; if (a[0]==c[2]) count2++; if (a[1]==c[0]) count2++; if (a[1]==c[2]) count2++; if (a[2]==c[0]) count2++; if (a[2]==c[1]) count2++; cout << count2 << " ball" << endl; if (count == 3) { cout << "삼진 아웃!!"<