์ƒˆ์†Œ์‹

Languages/C++

[C++] ์ค‘๋ณต ๊ฐ€๋Šฅ ๋กœ๋˜, ์ค‘๋ณต ๋ถˆ๊ฐ€๋Šฅ ๋กœ๋˜ ์‹ค์Šต

  • -
๋ฐ˜์‘ํ˜•

์ฝ”๋“œ

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;

int big (int a, int b){
	if(a>b) return a;
	else return b;
}

int big(int a[], int size){
	int res = a[0];
	for(int i = 1; i<size; i++)
		if(res < a[i]) res = a[i];
	return res;
}
int small (int a, int b){
	if(a>b) return b;
	else return a;
}

int small(int a[], int size){
	int res = a[0];
	for(int i = 1; i<size; i++)
		if(res > a[i]) res = a[i];
	return res;
}

void lotto(int y[], string s,int size=6){
/*	for(int i=0; i< size; i++){
		if(s == "์ค‘๋ณต ๋ถˆ๊ฐ€๋Šฅ ๋กœ๋˜"){
			์ค‘๋ณต ์ œ๊ฑฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜
			int res = y[0];
			for(int i = 1; i<size; i++){
				if(res == y[i]) --i;
			}
		}
		
		int r = rand()%45+1;
		cout<<r<<endl;
	}
	cout <<size<<endl;
*/	
	if(s =="๋กœ๋˜ ์ค‘๋ณต ๊ฐ€๋Šฅ"){
		cout<<"์ค‘๋ณต ๊ฐ€๋Šฅ ๋กœ๋˜ : ";
		for(int i =0; i<size; i++){
			y[i]=rand()%45+1;
			cout<<y[i]<<", ";
		}	
		cout<<endl; 
	}else {
	//	y[0] = rand()%45+1;
		for(int i =1; i<size; i++){
			y[i]=rand()%45+1;
			for(int j = 0;j<i;j++){
				if(y[i]==y[j]){
					--i;
					break;
				}
			}
		}
		cout<<endl<<"์ค‘๋ณต ๋ถˆ๊ฐ€ ๋กœ๋˜ : ";
		for (int i = 0;i<size;i++){
			cout<<y[i]<<", " ;
		}	
	}

}
int main()
{
	
	//int ar[] = {1,8,-3,4,6,7,8,6,4,56,4};
	//cout<<big(2,3)<<endl;
	//cout<<"์ตœ๋Œ€ ๊ฐ’ : "<<big(ar,sizeof(ar)/sizeof(ar[0]))<<endl;
	//cout<<small(2,3)<<endl;
	//cout<<"์ตœ์†Œ ๊ฐ’ : "<<small(ar,sizeof(ar)/sizeof(ar[0]))<<endl;
	
	srand(time(NULL));
//	int r = rand()%100+1;//1~100 ์‚ฌ์ด์˜ ์ž„์˜์˜ ์ˆ˜ 
//	cout<<r<<endl;
	int x[6];
	lotto(x,"๋กœ๋˜ ์ค‘๋ณต ๊ฐ€๋Šฅ" );
	lotto(x,"์ค‘๋ณต ๋ถˆ๊ฐ€๋Šฅ ๋กœ๋˜", sizeof(x)/sizeof(x[0]));
	 
	return 0;
}

 

๊ฒฐ๊ณผ

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.