1 #include <iostream> 2 #include <vector> 3 #include <time.h> 4 using namespace std; 5 6 7 int main() 8 { 9 // 랜덤 돌릴 범위의 모든 숫자를 저장한다. 10 vector<int> LottoNum; 11 for (int i = 0; i < 50; ++i) 12 LottoNum.push_back((i+1)); 13 14 vector<int> ResultLottoNum; // 램덤 후 결과값 담을 벡터 15 int NumRand = 0; 16 17 srand((unsigned)time(0)); 18 19 for (int i = 0; i < 25; ++i) 20 { 21 vector<int>::iterator vcItr; 22 23 int SelectRandNum = 0; 24 SelectRandNum = rand()%LottoNum.size(); //랜덤 25 26 vcItr = LottoNum.begin() + SelectRandNum; // iterator에 램덤 위치 값 가르키도록 지정. 27 28 NumRand = *vcItr; //값을 저장. 29 cout << NumRand << " / "; 30 31 if ((i+1)%5 == 0) 32 cout << endl; 33 ResultLottoNum.push_back(NumRand); //최종 결과값 저장 벡터에 데이터 넣기. 34 35 LottoNum.erase(vcItr); // 중복되지 않도록 삭제 처리. 36 } 37 return 0; 38 } 39 40
'Languages > cplusplus' 카테고리의 다른 글
지수표기 / enum / new 메모리 할당 (0) | 2012.10.12 |
---|---|
데이터 형변환 (0) | 2012.09.26 |
[MFC] Dialog Box (대화 상자) (0) | 2012.08.09 |
[MFC] List Control 사용법 정리 (1) | 2012.08.09 |
비트 연산자는 어디에 사용되는가? (0) | 2012.04.16 |