No older revisions available
No older revisions available
데블스 캠프 첫째날 랜덤 숫자야구 코드
첫번째 방법
~cpp #include <iostream> #include <ctime> using namespace std; int main() { srand(time(0)); int solution[3]; int i; do { i=0; while (i<3) { solution[i]= rand() % 10; ++i; } }while (solution[0]==solution[1] || solution[1]==solution[2] || solution[0]==solution[2]); cout << "정답 : " << int(solution[0]) << int(solution[1]) << int(solution[2]) << endl; int strike,ball,temp; int answer[3]; while (strike<3) { strike=0, ball=0; cin >> temp; answer[0]=temp/100; answer[1]=(temp%100)/10; answer[2]=temp%10; for (int i=0 ; i<3 ; i++) { if (solution[i]==answer[i]) { strike++; continue; } for (int j=0 ; j<3 ; j++) if (solution[j]==answer[i]) ball++; } cout << "strike : " << strike << "\tball : " << ball << endl; } return 0; }