본문 바로가기

C++ in Windows/ETC

[콘솔] 로또 번호 추출




오늘 급 로또를 사려 하는데 번호를 고르기 난감해서.

간단하게 콘솔로 만듬.



#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <vector>
#include <algorithm>

using namespace std;

void main (void)
{
	int num = 0;
	srand(time(NULL));

	printf("원하는 로또 갯수를 입력하세요.\n> ");
	scanf("%d", &num);

	vector<int> numbers;
	vector<int>::iterator itFind;

	for(int i = 0; i < num; i++)
	{
		for(int n = 0; n < 6; n++)
		{
			int rnd;
retry:
			rnd = rand() % 45 + 1;
			itFind = find( numbers.begin(), numbers.end(), rnd);

			if ( itFind == numbers.end() )
				numbers.push_back(rnd);
			else
				goto retry;

			printf("%d ", rnd);
			Sleep(rand()%2000+400);
		}

		sort(numbers.begin(), numbers.end());
		
		printf("---> ");
		for(int n = 0; n < 6; n++)
			printf("%d ", numbers[n]);

		printf("\n");

		numbers.clear();
		Sleep(100);
	}
	
	fflush(stdin);
	system("pause");
	
	return;
}




아래 exe 파일은 Visual Studio 2005에서 제작한 실행파일이다.

Lotto.exe


혹여나 실행이 안될경우. 아래 글에서 해당 패키지를 받아서 설치하면 된다.

Visual C++ 재배포 패키지

'C++ in Windows > ETC' 카테고리의 다른 글

Visual C++ 재배포 패키지  (0) 2014.06.02
[콘솔] 로또 번호 추출. 응용1.  (0) 2014.05.27