๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

[inflearn ๊ฐ•์˜] ๊ธฐ๋ณธ ๋ฌธ๋ฒ• - ๋กœ๋˜ ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

๐Ÿ‘ฉ‍๐Ÿ’ป IoT (Embedded)/C++

[inflearn ๊ฐ•์˜] ๊ธฐ๋ณธ ๋ฌธ๋ฒ• - ๋กœ๋˜ ๋งŒ๋“ค๊ธฐ

์ง•์ง•์•ŒํŒŒ์นด 2023. 6. 29. 01:37
728x90
๋ฐ˜์‘ํ˜•

<๋ณธ ๋ธ”๋กœ๊ทธ๋Š” ์–ด์†ŒํŠธ๋ฝ ๊ฒŒ์ž„์•„์นด๋ฐ๋ฏธ ๋‹˜์˜ ์œ ํŠœ๋ธŒ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค :-)>

=> C++ Let's Make Games

 

๐Ÿซง ๋กœ๋˜ 1

// Chapter1_10

#include <iostream>
using namespace std;

int main()
{
	// Lotto Program
	system("cls");
	srand((unsigned int)time(0));

	int iLotto[45] = {};

	// 1 ~ 45๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋„ฃ์–ด์ค€๋‹ค
	for (int i = 0; i < 6; i++) {
		cout << (rand() % 45 + 1) << endl;
	}
	return 0;
}

 

๐Ÿซง ๋กœ๋˜ 2

// Chapter1_10

#include <iostream>
using namespace std;

int main()
{
	// Lotto Program
	system("cls");
	srand((unsigned int)time(0));

	int iLotto[45] = {};

	// 1 ~ 45๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋„ฃ์–ด์ค€๋‹ค
	for (int i = 0; i < 45; i++) {
		iLotto[i] = i + 1;
	}

	// Swap ์•Œ๊ณ ๋ฆฌ์ฆ˜
/*	int iNum1 = 1, iNum2 = 2, iNum3;
	iNum3 = iNum1;
	iNum1 = iNum2;
	iNum2 = iNum3;*/

	// shuffle
	int iTemp, idx1, idx2;
	for (int i = 0; i < 100; i++) {
		idx1 = rand() % 45;
		idx2 = rand() % 45;

		iTemp = iLotto[idx1];
		iLotto[idx1] = iLotto[idx2];
		iLotto[idx2] = iTemp;
	} 
	for (int i = 0; i < 45; i++) {
		cout << iLotto[i] << endl;
	}
	return 0;
}

728x90
๋ฐ˜์‘ํ˜•
Comments